공부방/Elasticsearch

elasticsearch - search

daram 2022. 7. 6. 16:33

실습 자료는 아래에서 받으실 수 있습니다.

https://github.com/minsuk-heo/BigData/blob/master/ch03/simple_basketball.json

 

두개의 정보가 들어가 있는 파일이 존재한다. (simple_basketball.json)

한개는 점수가 30점, 한개는 점수가 20점이다.

 

아래의 코드로 bulk 데이터를 저장해보자

curl -XPOST 'localhost:9200/_bulk?pretty' 
--header 'content-type: application/
json'  --data-binary @simple_basketball.json

 

저장한 데이터를 다시 조회해보자.

curl -XGET localhost:9200/basketball/record/_search?pretty

 

아래에서 두개의 데이터가 잘 저장되어 있는 것을 확인할 수 있다.

 

point가 30인 것만 조회하고 싶다면 아래와 같이 쿼리를 다르게 날려볼 수 있다.

curl -XGET 'localhost:9200/basketball/record/_search?q=points:30&pretty'

 

 

curl -XGET 
--header 'content-type:application/json' 
'localhost:9200/basketball/record/_search?pretty' 
-d '{ "query" : { "term" : { "points" : 30 } } }'

 

 

 

더욱 자세한 내용은 아래에서 확인할 수 있다.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html