2.X/6. Modeling Your Data

6-3. Parent-Child Relationship

drscg 2017. 9. 23. 14:37

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와 또 다른 것을 관련짓는다. 차이점은 nested 오브젝트는 모든 entity가 동일한 document내에 존재하는 반면에, 부모-자식은 부모와 자식이 완전히 구분된 document라는 점이다.

The parent-child functionality allows you to associate one document type with another, in a one-to-many relationship—one parent to many children. The advantages that parent-child has over nestedobjects are as follows:

부모-자식 기능은, 어떤 document type과 또 다른 type을, 1:n(one-to-many, 하나의 부모와 많은 자식) 관계로 관련짓는다. 부모-자식이, nested objects에 대해, 가지는 장점은 아래와 같다.

  • The parent document can be updated without reindexing the children.

    부모 document는 자식을 재색인하지 않고 업데이트될 수 있다.

  • Child documents can be added, changed, or deleted without affecting either the parent or other children. This is especially useful when child documents are large in number and need to be added or changed frequently.

    자식 document는 부모나 다른 자식에 영향을 주지 않고, 추가, 수정, 삭제될 수 있다. 이것은 자식 document가 많거나, 자주 추가 또는 변경되는 경우에 특히 유용하다.

  • Child documents can be returned as the results of a search request.

    자식 document는 검색 request의 결과로서 반환될 수 있다.

Elasticsearch maintains a map of which parents are associated with which children. It is thanks to this map that query-time joins are fast, but it does place a limitation on the parent-child relationship: the parent document and all of its children must live on the same shard.

Elasticsearch는 어떤 부모가 어떤 자식과 관련되어 있는지를 map으로 유지한다. 검색 시에 join이 빠른 것은 이 map 때문이다. 그러나 부모-자식 관계는 제한이 있다. 부모 document와 그것의 자식 document 모두는 반드시 동일한 shard내에 있어야 한다.

The parent-child ID maps are stored in Doc Values, which allows them to execute quickly when fully hot in memory, but scalable enough to spill to disk when the map is very large.

부모-자식의 ID map은 Doc Values에 저장된다. 이것은 그들이 모두 메모리에 있을때, 빨리 실행되도록 한다. 그러나, map이 매우 클 경우 디스크로 확장된다.

'2.X > 6. Modeling Your Data' 카테고리의 다른 글

6-2-3. Sorting by Nested Fields  (0) 2017.09.23
6-2-4. Nested Aggregations  (0) 2017.09.23
6-3-1. Parent-Child Mapping  (0) 2017.09.23
6-3-2. Indexing Parents and Children  (0) 2017.09.23
6-3-3. Finding Parents by Their Children  (0) 2017.09.23