Elasticsearch로 검색하기

MiniDeveloper·2022년 1월 24일
0

Elasticsearch

목록 보기
7/7

예제 코드인 simple_basketball.json
을 넣어보자.

     { "index" : { "_index" : "basketball", "_type" : "record", "_id" : "1" } }
     {"team" : "Chicago Bulls","name" : "Michael Jordan", "points" : 30,"rebounds" : 3,"assists" : 4, "submit_date" : "1996-10-11"}
     { "index" : { "_index" : "basketball", "_type" : "record", "_id" : "2" } }
     {"team" : "Chicago Bulls","name" : "Michael Jordan","points" : 20,"rebounds" : 5,"assists" : 8, "submit_date" : "1996-10-11"}

이 파일로 index를 만들어보자

curl -XPOST -H "Content-Type: application/json" http://localhost:9200/_bulk?pretty --data-binary @simple_basketball.json

등록된 index 조회

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

Point가 30인 값만 검색하기

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

아래처럼 points가 30인 값만 검색되는 것을 확인할 수 있다.

쿼리문을 아래와 같이 전달 가능하다

curl -XGET -H "Content-Type: application/json" "localhost:9200/basketball/record/_search?pretty" -d'{"query":{"term":{"points":30}}}'
profile
미니 개발자의 개발 일기

0개의 댓글