Because nested objects are indexed as separate hidden documents, we can’t query them directly.Instead, we have to use the nested query to access them:
nested object는 숨겨진 개별 document로 색인되기 때문에, 그들을 직접 query할 수 없다. 대신에, 그들을 nested query를 사용하여 액세스해야 한다.
GET /my_index/blogpost/_search { "query": { "bool": { "must": [ { "match": { "title": "eggs"} }, { "nested": { "path": "comments",
"query": { "bool": { "must": [
{ "match": { "comments.name": "john" } }, { "match": { "comments.age": 28 } } ] } } } } ] }}}
| |
| |
|
A nested field can contain other nested fields. Similarly, a nested query can contain other nested queries. The nesting hierarchy is applied as you would expect.
nested field는 다른 nested field를 포함할 수 있다. 유사하게, nested query는 다른 nested query를 포함할 수 있다. 중첩(nesting) 체계는 원하는 대로 적용될 수 있다.
Of course, a nested query could match several nested documents. Each matching nested document would have its own relevance score, but these multiple scores need to be reduced to a single score that can be applied to the root document.
물론, nested query는 다수의 nested document와 일치할 수 있다. 각각의 일치하는 nested document는 각자의 relevance score를 가진다. 하지만, 이들 다수의 score는 root document에 적용될 수 있도록, 단일 score로 축소되어야 한다.
By default, it averages the scores of the matching nested documents. This can be controlled by setting the score_mode parameter to avg, max, sum, or even none (in which case the root document gets a constant score of 1.0).
기본적으로, 그것은 일치하는 nested document에서 계산된 score의 평균이다. 이것은 score_mode 매개변수에 avg, max, sum 또는 none(이 경우, root document는 항상 score 1.0 을 갖는다)을 설정하여, 제어할 수 있다.
GET /my_index/blogpost/_search { "query": { "bool": { "must": [ { "match": { "title": "eggs" } }, { "nested": { "path": "comments", "score_mode": "max","query": { "bool": { "must": [ { "match": { "comments.name": "john" } }, { "match": { "comments.age": 28 } } ] } } } } ] } } }
If placed inside the filter clause of a Boolean query, a nested query behaves much like a nested query, except that it doesn’t accept the score_mode parameter. Because it is being used as a non-scoring query — it includes or excludes, but doesn’t score — a score_mode doesn’t make sense since there is nothing to score.
boolean query의 filter 절 내부에 위치한다면, score_mode 를 가지지 않는다는 점을 제외하면, nested query는 훨씬 nested query처럼 동작한다. non-scoring query처럼 사용되기 때문이다. — 포함 여부만 판단하며, score를 계산하지는 않는다 — score_mode 는 score를 계산할 것이 없기 때문에 적절하지 않다.
'2.X > 6. Modeling Your Data' 카테고리의 다른 글
| 6-2. Nested Objects (0) | 2017.09.23 |
|---|---|
| 6-2-1. Nested Object Mapping (0) | 2017.09.23 |
| 6-2-3. Sorting by Nested Fields (0) | 2017.09.23 |
| 6-2-4. Nested Aggregations (0) | 2017.09.23 |
| 6-3. Parent-Child Relationship (0) | 2017.09.23 |