Let’s make the search a little more complicated. We still want to find all employees with a last name of Smith, but we want only employees who are older than 30. Our query will change a little to accommodate a filter, which allows us to execute structured searches efficiently:
약간 더 복잡한 검색을 해 보자. last name이 Smith인 모든 직원을 찾으면서, 나이가 30보다 많은 직원을 찾으려 한다. query는 구조화된 검색을 효율적으로 실행할 수 있는 filter 를 넣기 위해, 약간 변경된다.
GET /megacorp/employee/_search { "query" : { "bool" : { "must" : { "match" : { "last_name" : "smith"} }, "filter" : { "range" : { "age" : { "gt" : 30 }
} } } } }
Don’t worry about the syntax too much for now; we will cover it in great detail later. Just recognize that we’ve added a filter that performs a range search, and reused the same match
query as before. Now our results show only one employee who happens to be 32 and is named Jane Smith:
지금은 문법에 대해 너무 신경 쓰지 말자. 나중에 훨씬 더 자세히 다룰 것이다. 단지, 범위 검색을 위해 filter를 추가했다는 것과, 이전의 match
query를 다시 사용했다는 것만 알아두자. 결과는 이름이 Jane Smith이고, 나이가 32인 한 명의 직원을 보여준다.
{ ... "hits": { "total": 1, "max_score": 0.30685282, "hits": [ { ... "_source": { "first_name": "Jane", "last_name": "Smith", "age": 32, "about": "I like to collect rock albums", "interests": [ "music" ] } } ] } }
'2.X > 1. Getting Started' 카테고리의 다른 글
1-01-07. Search Lite (0) | 2017.10.01 |
---|---|
1-01-08. Search with Query DSL (0) | 2017.10.01 |
1-01-10. Full-Text Search (0) | 2017.10.01 |
1-01-11. Phrase Search (0) | 2017.10.01 |
1-01-12. Highlighting Our Searches (0) | 2017.10.01 |