Elasticsearch | Nested-VS-ParentJoin

本文整理自网络。

parent-join 适用场景

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.

子文档可以被添加,修改,删除且不会影响其他父文档和其他子文档。 这在子文档数据很大且需要被添加和频繁修改的场景尤其适用。

不同

Nested&Join父子文选型必须考虑性能问题。 nested 类型检索使得检索效率慢几倍,父子Join 类型检索会使得检索效率慢几百倍。

在这里插入图片描述

The parent-child relationship is similar in nature to the nested model: both allows us 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. However, it also is bound to some restrictions:

不同在于,nested objects 所有的实体在一个文档中,而parent-child 父文档和子文档是在不同的文档中。

Nested Object Parent-Child
保存在同一个文档(document)中 保存在不同的文档中
一个孩子对象可以有多个父对象 一个孩子对象不可以有多个父对象
查询相对快 查询很慢,因为父子文档保存在不同的文档中
很容易维护多级网络 很难维护多级网络
nested级别的查询很明确,使用简单 当有多个父子关系的时候查询变得复杂
可以查询所有的数据 不能在一个查询中同时查询父级和子级文档
每个父级对象有复制 不涉及数据重复
如果一个nested对象改变了,所有的父级对象都需要重建索引 不需要重建索引,因为只维护了一个连接

Parent - Child 限制

The parent and child types must be different or parent-child relationships cannot be established between documents of the same type.

父类型(type)和子类型必须不同,或者父子关系不同创建在不同文档的同一type中。

Parent and child documents must be indexed on the same shard. The parent ID is used as the routing value for the child, to ensure that the child is indexed on the same shard as the parent. This means that the same parent value needs to be provided when getting, deleting, or updating a child document.

父子文档必须索引在同一个分片上。父文档的 id 被用到索引子文档,来确保父子文档索引在同一个分片上。 这意味着当获取、删除或者修改一个子文档的时候需要提供相同的 parent 的值。

来源:https://www.javazhiyin.com/35760.html

https://qbox.io/blog/elasticsearch-performance-considerations-parent-child-relationships

猜你喜欢

转载自blog.csdn.net/Prepared/article/details/90690318
今日推荐