파워노트

Elasticsearch 사용법 본문

ElasticSearch

Elasticsearch 사용법

파워킴 2020. 11. 10. 15:17
반응형

##### index 생성

curl -XPUT 'localhost:9200/customer?pretty'

#index 생성 및 id document 생성 

curl -XPOST 'localhost:9200/customer2/info/1?pretty' -H 'Content-Type: application/json' -d '{
"name": "victolee"
}'

# id 가 없는 경우 임의의 id 생성

curl -XPOST 'localhost:9200/customer2/info?pretty' -H 'Content-Type: application/json' -d '{
"name": "victolee2"
}'

# File생성이후 File load하여 document 생성.

vi data.json
{
"name": "victory",
"address": "경기도",
"phone": "010-123-1234",
"reg_date": "2019-03-31"
}

 

curl -XPOST 'localhost:9200/customer2/info/2?pretty' -H 'Content-Type: application/json' -d data.json

 

##### Document 조회
# index로 조회

curl -XGET 'localhost:9200/customer2/_search?pretty'
# type으로 조회

curl -XGET 'localhost:9200/customer2/info/_search?pretty'
# id으로 조회

curl -XGET 'localhost:9200/customer2/info/1?pretty'
# 모든 Document 조회 (_all)
curl -XGET 'localhost:9200/_all/_search?pretty'

# 조건조회 
curl -XGET 'localhost:9200/customer2/info/1?pretty&filter_path=_source'

curl -XGET 'localhost:9200/customer2/info/1?pretty&filter_path=_source.name'

 

###### Update 

curl -XPUT 'localhost:9200/customer2/info/1?pretty' -H 'Content-Type: application/json' -d '{
"name": "victolee_update"
}'

###### 삭제 
# id로 document 삭제
curl -XDELETE 'localhost:9200/customer2/info/1?pretty'

# index 삭제 
curl -XDELETE 'localhost:9200/customer2?pretty'

 

 

 

참고 URL : victorydntmd.tistory.com/312 

반응형

'ElasticSearch' 카테고리의 다른 글

bootstrap checks failed vm.max_map_count 관련  (0) 2020.11.27
logstash 기본 사용  (0) 2020.11.26
ElasticSearch index Mapping  (0) 2020.11.10
ElasticSearch max_result_window 설정  (0) 2020.11.10
Comments