2.X/1. Getting Started
1-01-11. Phrase Search
drscg
2017. 10. 1. 12:10
Finding individual words in a field is all well and good, but sometimes you want to match exact sequences of words or phrases. For instance, we could perform a query that will match only employee records that contain both "rock" and "climbing" and that display the words next to each other in the phrase "rock climbing".
특정 field에서 개별적인 단어를 찾는 것은 잘 된다. 하지만 가끔씩 정확한 순서의 단어들이나 구(句, phrases) 로 일치하기를 원한다. 예를 들어, "rock" 과 "climbing" 양쪽 모두를 포함하고 , 그 단어들이 "rock climbing" 처럼 서로 옆에 위치하는 직원만이 일치하는 query를 실행할 수 있다.
To do this, we use a slight variation of the match
query called the match_phrase
query:
이를 위해, 아래처럼 match
query를 약간 변형한 match_phrase
query를 사용한다.
GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } } }
This, to no surprise, returns only John Smith’s document:
이 query는 당연히 John Smith의 document만을 반환한다.
{ ... "hits": { "total": 1, "max_score": 0.23013961, "hits": [ { ... "_score": 0.23013961, "_source": { "first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": [ "sports", "music" ] } } ] } }