-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chapter43_part1: /404_Parent_Child/40_Parent_child.asciidoc #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0b74749
181a79d
8f44a6f
655eb6d
4bf0ce8
b9172c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,29 @@ | ||
[[parent-child]] | ||
== Parent-Child Relationship | ||
== 父-子关系文档 | ||
|
||
The _parent-child_ relationship is ((("relationships", "parent-child")))((("parent-child relationship")))similar in nature to the | ||
<<nested-objects,nested model>>: both allow you to associate one entity | ||
with another. ((("nested objects", "parent-child relationships versus")))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. | ||
父-子关系文档((("relationships", "parent-child")))((("parent-child relationship")))和 | ||
<<nested-objects,nested model>> 有一个相似点:允许将一个对象实体和另外一个对象实体关联起来。((("nested objects", "parent-child relationships versus")))而这两种类型的主要区别是:在 在 <<nested-objects,`nested` objects>> 文档中,所有对象都是在同一个文档中,而在父-子关系文档中,父对象和子对象都是完全独立的文档。 | ||
|
||
The parent-child functionality allows you to associate one document type with | ||
another, in a _one-to-many_ relationship--one parent to many children.((("one-to-many relationships"))) The | ||
advantages that parent-child has over <<nested-objects,`nested` objects>> are as follows: | ||
父-子关系的主要作用是允许把一个 type 的文档和另外一个 type 的文档关联起来,构成1对n的关系:一个父文档可以对应多个子文档((("one-to-many relationships")))。与 <<nested-objects,`nested` objects>> 相比,父-子关系的主要优势有: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议:1. 这里document就是指type,翻译中去掉type的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 关于第一条,我觉得type保留下来,能够更加清楚地说明P-C是关联不同type类型的文档(而不是用来关联同一个type下的不同文档)。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可能一对多更好,当然1对多也看得懂 |
||
|
||
* The parent document can be updated without reindexing the children. | ||
* 更新父文档时,不会重新索引子文档。 | ||
* 创建,修改或删除子文档时,不会影响父文档和其他子文档。这一点在这种场景下尤其有用:子文档数量较多,并且子文档创建和修改的频率高时。 | ||
* 子文档可以作为搜索结果,独立返回。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 父文档或其他子文档 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按照给出的建议修改 |
||
|
||
* 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. | ||
Elasticsearch 维护了一个父文档和子文档的映射关系——ID maps,实现了快速的父-子文档查询操作。但是,有一点需要指出:父文档和其所有子文档,都必须要存储在同一个分片中。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议:1. 去掉——ID maps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按照给出的建议修改 |
||
|
||
* Child documents can be returned as the results of a search request. | ||
ID maps 维护在 <<docvalues>> 中。通过 <<docvalues>>,可以将热点查询的 ID maps 维护在内存中;当 ID maps 变得非常大时,还可以将其扩展加载到硬盘中。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 第1个建议按照要求修改。第2个在请教中 |
||
|
||
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_. | ||
|
||
The parent-child ID maps are stored in <<docvalues>>, which allows them to execute | ||
quickly when fully hot in memory, but scalable enough to spill to disk when | ||
the map is very large. | ||
|
||
|
||
[[parent-child-mapping]] | ||
=== Parent-Child Mapping | ||
=== 父-子映射 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 父-子文档映射 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按照给出的建议修改 |
||
|
||
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.((("mapping (types)", "parent-child")))((("parent-child relationship", "parent-child mapping"))) This must | ||
be done at index creation time, or with the `update-mapping` API before the | ||
child type has been created. | ||
建立父-子映射关系时需要指定某一个文档 type 是另一个文档 type 的父亲。((("mapping (types)", "parent-child")))((("parent-child relationship", "parent-child mapping")))该关系可以在如下两个时间点设置:1)创建索引时;2)在子文档的 type 创建之前,通过更新父文档的 mapping。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.只需要 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 按照给出的建议修改 |
||
|
||
As an example, let's say that we have a company that has branches in many | ||
cities. We would like to associate employees with the branch where they work. | ||
We need to be able to search for branches, individual employees, and employees | ||
who work for particular branches, so the nested model will not help. We | ||
could, of course, | ||
use <<application-joins,application-side-joins>> or | ||
<<denormalization,data denormalization>> here instead, but for demonstration | ||
purposes we will use parent-child. | ||
举例说明,有一个公司在多个城市有分公司,并且每一个分公司下面都有很多员工。有这样的需求:按照分公司、员工的维度去搜索,并且搜索某些特定分公司下的员工。针对该需求,用嵌套模型是无法实现的。当然,如果使用 <<application-joins,application-side-joins>> 或者 <<denormalization,data denormalization>> 也是可以实现的。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
|
||
All that we have to do is to tell Elasticsearch that the `employee` type has | ||
the `branch` document type as its `_parent`, which we can do when we create | ||
the index: | ||
在这里我们使用父-子文档,首先需要父子文档的映射关系,我们在创建员工 `employee` 文档 type 时,指定分公司 `branch` 的文档 type 为其父亲。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
|
||
[source,json] | ||
------------------------- | ||
|
@@ -64,4 +39,4 @@ PUT /company | |
} | ||
} | ||
------------------------- | ||
<1> Documents of type `employee` are children of type `branch`. | ||
<1> `employee` 文档 是 `branch` 文档的子文档。 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议:1. 改成在实质上类似于xxx
2. (((这种符号好像都要留空格
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, 按照给出的建议修改