2.X/6. Modeling Your Data 35

6-2-3. Sorting by Nested Fields

It is possible to sort by the value of a nested field, even though the value exists in a separate nested document. To make the result more interesting, we will add another record: 값은 개별 nested document에 있지만, nested field의 값으로 정렬하는 것은 가능하다. 더 흥미로운 결과를 만들어내기 위하여, 또 다른 document를 추가해 보자.PUT /my_index/blogpost/2 { "title": "Investment secrets", "body": "What they don't tell you ...", "tags": [ "share..

6-2-4. Nested Aggregations

In the same way as we need to use the special nested query to gain access to nested objects at search time, the dedicated nested aggregation allows us to aggregate fields in nested objects: 검색 시에, nested object에 액세스하기 위해, 특별히 nested query를 사용해야 하는 것과 동일한 방식으로, nested object에 있는 field를 aggregation하기 위한, 전용 nested aggregation이 있다.GET /my_index/blogpost/_search { "size" : 0, "aggs": { "comments": {..

6-3. Parent-Child Relationship

The parent-child relationship is similar in nature to the nested model: both allow you to associate one entity with another. The difference is that, with nested objects, all entities live within the same document while, with parent-child, the parent and children are completely separate documents.parent-child relationship(부모-자식 관계)은 본질적으로 nested model과 유사하다. 둘 모두는 어떤 entity와 또 다른 것을 관련짓는다. 차이점은 n..

6-3-1. Parent-Child Mapping

All that is needed in order to establish the parent-child relationship is to specify which document type should be the parent of a child type. This must be done at index creation time, or with the update-mapping API before the child type has been created.부모-자식 관계를 형성하기 위해 필요한 것은, 어떤 document type이 자식 type의 부모가 될 것인지를 지정하는 것이다. 이것은 index 생성시에 하거나, 자식 type이 생성되기 전에 update-mapping API를 통해 할 수 있다.As..

6-3-2. Indexing Parents and Children

Indexing parent documents is no different from any other document. Parents don’t need to know anything about their children:부모 document를 색인 하는 것은 다른 document와 다르지 않다. 부모는 그들의 자식에 대해 아무것도 알 필요가 없다.POST /company/branch/_bulk { "index": { "_id": "london" }} { "name": "London Westminster", "city": "London", "country": "UK" } { "index": { "_id": "liverpool" }} { "name": "Liverpool Central", "city": "..

6-3-3. Finding Parents by Their Children

The has_child query and filter can be used to find parent documents based on the contents of their children. For instance, we could find all branches that have employees born after 1980 with a query like this:has_child query와 filter는 자식의 내용으로 부모 document를 찾는데 사용될 수 있다. 예를 들어, 1980년 이후에 태어난 직원을 가진, 모든 지점을 찾을 수 있다. query는 아래와 같다.GET /company/branch/_search { "query": { "has_child": { "type": "empl..

6-3-4. Finding Children by Their Parents

While a nested query can always return only the root document as a result, parent and child documents are independent and each can be queried independently. The has_child query allows us to return parents based on data in their children, and the has_parent query returns children based on data in their parents.nested query는 결과로 root document만 반환하지만, 부모와 자식 document는 독립적이며, 각각 독립적으로 query될 수 있다. h..

6-3-5. Children Aggregation

Parent-child supports a children aggregation as a direct analog to the nested aggregation discussed in Nested Aggregations. A parent aggregation (the equivalent of reverse_nested) is not supported.부모-자식은, Nested Aggregations에서 언급했던, nested aggregation과 정확히 닮은, children aggregation를 지원한다. parent aggregation(reverse_nested 와 비슷한)는 지원되지 않는다.This example demonstrates how we could determine the favor..

6-3-6. Grandparents and Grandchildren

The parent-child relationship can extend across more than one generation—grandchildren can have grandparents—but it requires an extra step to ensure that documents from all generations are indexed on the same shard.부모-자식 관계는 한 세대이상으로 확장(손자는 조부모를 가질 수 있다)될 수 있다. 그러나, 모든 세대의 document가 동일한 shard에 색인되는지를 보장하기 위한, 추가 단계가 필요하다.Let’s change our previous example to make the country type a parent of the ..

6-3-7. Practical Considerations

Parent-child joins can be a useful technique for managing relationships when index-time performance is more important than search-time performance, but it comes at a significant cost. Parent-child queries can be 5 to 10 times slower than the equivalent nested query!부모-자식의 join은, 색인 시의 성능이 검색 시의 성능보다 중요한 경우에, 관계를 관리하는 유용한 기술이다. 그러나 상당한 비용이 발생한다. 부모-자식 query는 동급의 nested query에 비해 5 ~ 10배 정도 더 느릴 수..