StoryCode

모든 색인 나열/ 생성

Elastic Search
반응형

1. 색인 나열

> curl http://127.0.0.1:9200/_cat/indices?v


health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

# 색인이 없는 상태

 

2. 색인 생성

> curl -X PUT http://127.0.0.1:9200/customer?pretty # pretty =JSON응답을 pretty-print

{
  "acknowledged" : true,
  "shards_acknowledged" : true
}

 

> curl http://127.0.0.1:9200/_cat/indices?v
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   customer 7K4E9D24SKmUMznoVYcL7w   5   1          0            0       650b           650b

# customer 라는 색인이 하나 있으며, pri shard = 5개, replica = 1개.

# yellow : replica = 1 인데, 노드가 1개뿐임. 노드 추가해야 green 이 됨.

 

 

 

3. 문서 색인화 및 쿼리

호줄할 내용)

PUT /customer/external/1?pretty

{

    "name": "John Doe"

}

 

호출 방법 1.curl)

curl -X PUT -H "Content-Type: application/json; charset=utf-8" -d '{"name":"John Doe"}' http://172.16.174.148:9200/customer/external/1?pretty

 

호출 방법 2.postman)

  PUT + http://172.16.174.148:9200/customer/external/1?pretty 선택

  BODY + raw + json 선택

  { "name": "John Doe" } 입력

 

결과)

{
  "_index" : "customer",
  "_type" : "external",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}

 

* 같은 ID ( 위 경우에는 1 ) 로 한 번 더 호출하면 (이름을 바꿔서) 업데이트(DELETE+INSERT)가 됨.

 

4) 앞서 id=1 로 했으나, 지정하지 않을 수 있다. 이 경우 Random ID 가 사용된다. ( POST 사용)

 

POST /customer/external?pretty
{
  "name": "Jane Doe"
}

 

{
    "_index": "customer",
    "_type": "externa",
    "_id": "AWpnuFPmHm_5zNNoJ_8z",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "created": true
}

 

5) 문서 업데이트

- 문서 업데이트

POST /customer/external/1/_update?pretty

{

  "doc":{"name":"Jane Doe"}

}

- 문서 업데이트 및 필드 추가

POST /customer/external/1/_update?pretty

{

  "doc":{"name":"Jane Doe","age":20}

}

 

- 스크립트를 이용한 업데이트

POST /customer/external/1/_update?pretty

{

  "script":"ctx._source.age += 5"

}

 

6) 문서 삭제

- 한 ID 삭제

DELETE /customer/external/2?pretty

 

- 매칭 삭제

  https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-delete-by-query.html

POST twitter/_delete_by_query
{
  "query": { 
    "match": {
      "message": "some message"
    }
  }
}

 

- 전체 삭제

POST twitter,blog/tweet,post/_delete_by_query
{
  "query": {
    "match_all": {}
  }
}

 

7) 배치 처리

- 2개의 Document 인덱싱 처리

POST /customer/external/_bulk?pretty

{"index":{"_id":"1"}}

{"name":"John Doe"}

{"index":{"_id":"2"}}

{"name":"Jane Doe"}

 

- 업데이트와 딜리트 동시 처리. 오류나도 처리는 계속됨. 처리결과반환시에 알수 있음.

POST /customer/external/_bulk?pretty

{"update":{"_id":"1"}}

{"doc":{"name":"John Doe becomes Jane Doe"}}

{"delete":{"_id":"2"}}

 

반응형

'Elastic Search' 카테고리의 다른 글

검색 실행  (0) 2019.04.30
데이터 탐색.샘플데이터 집합 로드  (0) 2019.04.29
매뉴얼-https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html  (0) 2019.04.28
클러스터 상태 보기  (0) 2019.04.28
설치  (0) 2019.04.28

매뉴얼-https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

Elastic Search
반응형

 

 

https://www.elastic.co/guide/kr/index.html

  https://www.elastic.co/guide/kr/elasticsearch/reference/current/index.html 

  https://www.elastic.co/guide/kr/logstash/current/index.html

  https://www.elastic.co/guide/kr/kibana/current/index.html

 

 

반응형

'Elastic Search' 카테고리의 다른 글

데이터 탐색.샘플데이터 집합 로드  (0) 2019.04.29
모든 색인 나열/ 생성  (0) 2019.04.28
클러스터 상태 보기  (0) 2019.04.28
설치  (0) 2019.04.28
Elastic Search 란  (0) 2019.04.18

클러스터 상태 보기

Elastic Search
반응형

1. curl http://127.0.0.1:9200/_cat/health?v

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1556456126 12:55:26  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%

 

# elasticsearch 가 green 임을 확인 가능.

 

색상 : green/ yellow/ red

녹색 모두 양호한 상태(클러스터가 정상 작동 중)
노란색 모든 데이터가 사용 가능한 상태이지만 일부 리플리카가 아직 배정되지 않은 상태(클러스터는 정상 작동 중)
빨간색

어떤 이유로 일부 데이터가 사용할 수 없는 상태

클러스터가 빨간색이더라도 아직 부분적으로 작동하는 중. = 사용 가능 샤드에서 계속 검색 요청을 처리.

 

데이터가 누락되므로 서둘러 문제를 해결해야 합니다.

 

2. curlcurl http://127.0.0.1:9200/_cat/nodes?v

ip             heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.16.174.148            8          40   0    0.01    0.01     0.00 mdi       *      0l3cD0_

 

# 이 클러스트에는 노드="0l3cD0_" 가 유일.

 

 

반응형

설치

Elastic Search
반응형

1. 환경

Ubuntu 18.10 liveserver

 

2. ElasticSearch 매뉴얼 페이지 참조

https://www.elastic.co/guide/kr/elasticsearch/reference/current/gs-installation.html

 

3. Java 11 설치

참조 : https://tecadmin.net/install-oracle-java-11-ubuntu-18-04-bionic/

> sudo apt update

> sudo apt upgrade

> sudo add-apt-repository ppa:linuxuprising/java

> sudo apt update

> sudo apt install oracle-java11-installer

> sudo apt install oracle-java11-set-default

> java -version

 

4. Elastic Search 설치

> mkdir download

> cd download

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.3.tar.gz

   # 혹은 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz

> cd /usr/local

> tar zxvf ~/download/elasticsearch-5.4.3.tar.gz

   # tar zxvf ~/download/elasticsearch-7.0.0-linux-x86_64.tar.gz

 

> grep vm.max_map_count /etc/sysctl.conf

> sudo sysctl -w vm.max_map_count=262144

# 각종 옵션 참조 https://okayjava.tistory.com/30 참조

cd elasticsearch-5.4.3/config

 

# 참조 : https://www.elastic.co/guide/en/elasticsearch/reference/2.3/setup-configuration.html

> vi config/elasticsearch.yml

   # 외부에서 접근가능하게 하려면 elastic 5.4.3 에서는 network.host: 0.0.0.0 으로 수정해야함. 7 에서는 모르겠음.

   # 보통은 kibana 통해서 접근하니 # 으로 막아놓채로 elasticsearch 실행할 것.

cd elasticsearch-5.4.3/bin

> ./elasticsearch # no root account, service elasticsearch restart

   # 클러스트/노드명 설정시 : ./elasticsearch -Ecluster.name=my_cluster_name -Enode.name=my_node_name

 

4.1

외부에서 접근 가능하면 Chrome> http://172.16.174.148:9200/ 확인.

아니면 localhost:9200으로만 접근 가능.

 

"name" : "0l3cD0_", "cluster_name" : "elasticsearch", "cluster_uuid" : "YFlzj7AiQcuZm73LyWIujQ", "version" : { "number" : "5.4.3", "build_hash" : "eed30a8", "build_date" : "2017-06-22T00:34:03.743Z", "build_snapshot" : false, "lucene_version" : "6.5.1" }, "tagline" : "You Know, for Search" }

 

5. curl 로 기본 상태 확인. ( _cat 은 Elastic Cluster 체크 명령 )

> curl http://127.0.0.1:9200/_cat/health?v

 

샘플결과>

poch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1556456126 12:55:26  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%

반응형