2019년 3월 28일 목요일

Elasticsearch - 자주 사용하는 명령어(CMD) 목록


검색 운영 업무중에 자주 사용하는 명령어(CMD) 목록을 정리해 본다.

목록

  1. Elasticsearch 관련
  2. Index 관련
  3. Alias 관련
  4. Document 유형 관련
  5. ReIndex API

1. Elasticsearch 관련

시작
 sudo /etc/init.d/elasticsearch start 

재시작
 sudo /etc/init.d/elasticsearch restart 

상태확인
 curl -XGET 'localhost:9200/' 


2. Index 관련

인덱스 확인
 curl -XGET 'localhost:9200/_cat/indices?v' 
설정 확인
 curl -XGET 'localhost:9200/{indexName}/_settings?pretty' 
맵핑 확인
 curl -XGET 'localhost:9200/{indexName}/_mapping?pretty' 
삭제
 curl -XDELETE 'localhost:9200/{indexName}?pretty' 


3. Alias 관련

Alias 확인
 curl -XGET 'localhost:9200/_aliases?pretty' 

4. Document 관련

문서 수 확인
 curl -sS -XGET 'localhost:9200/{indexName}/{typeName}/_count?pretty' 

필드추가
curl -XPUT 'localhost:9200/{indexName}/_mappings/{typeName}?pretty' -d '
{
  "properties" : {
    "field1" : {
      "type" : "long"
    },
    "field2" : {
      "type" : "date"
    }
  }
}'

벌크색인
curl -XPOST 'localhost:9200/{indexName}/{typeName}/_bulk?pretty' --data-binary @xxx.json


전체 데이터 삭제
curl -XPOST 'localhost:9200/{indexName}/{typeName}/_delete_by_query' --d '
{
  "query":{
    "match_all":{
    }
  }
}'

데이터 검색
curl -sS -XGET 'localhost:9200/{indexName}/{typeName}/_search?pretty'


데이터 검색 ((From-To 지정)
curl -sS -XGET 'localhost:9200/{indexName}/{typeName}/_search?pretty' -d '
{
  "query":{
    "match_all":{
    }
  },
  "from":0,
  "size":400
}'


데이터 갱신 (ID 지정)
curl -XPOST 'localhost:9200/{indexName}/{typeName}/{id}/_update' -d '
{
  "doc":{
    "field1": "test123"
  }
}'

데이터 일괄 업데이트
curl -XPOST 'localhost:9200/{indexName}/{typeName}/_update_by_query?conflicts=proceed&pretty' -d '
{
  "query":{
    "match_all": { }
  },
  "script":{
    "inline": "ctx._source.field1 = 'test123'"
  }
}'


5. ReIndex API

reindex
curl -XPOST 'localhost:9200/_reindex?pretty' -d '
{
  "source": {
    "index": "fromIndex"
  },
  "dest": {
    "index": "toIndex"
  }
}'


reindex (remote)
curl -XPOST 'localhost:9200/_reindex?pretty' -d '
{
  "source": {
    "remote": {
      "host": "http://otherhost:9200",
      "username": "user",
      "password": "pass"
    },
    "index": "fromIndex"
    }
  },
  "dest": {
    "index": "toIndex"
  }
}

댓글 없음:

댓글 쓰기