Skip to content

Commit cbd3630

Browse files
weiqiangyuantangmisi
authored and
tangmisi
committed
chapter43_part1: /404_Parent_Child/40_Parent_child.asciidoc (elasticsearch-cn#275)
* 完成Parent-Child第1部分的翻译 * revise nested model name * reisve pull request according to first inner team review * reisve pull request according to first inner team review * revise docvalue and maps * revise 1 to 一
1 parent 6d808ea commit cbd3630

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed
+13-41
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
11
[[parent-child]]
2-
== Parent-Child Relationship
2+
== 父-子关系文档
33

4-
The _parent-child_ relationship is ((("relationships", "parent-child")))((("parent-child relationship")))similar in nature to the
5-
<<nested-objects,nested model>>: both allow you to associate one entity
6-
with another. ((("nested objects", "parent-child relationships versus")))The difference is that, with nested objects, all entities live
7-
within the same document while, with parent-child, the parent and children
8-
are completely separate documents.
4+
父-子关系文档 ((("relationships", "parent-child"))) ((("parent-child relationship"))) 在实质上类似于 <<nested-objects,nested model>> :允许将一个对象实体和另外一个对象实体关联起来。((("nested objects", "parent-child relationships versus")))而这两种类型的主要区别是:在 <<nested-objects,`nested` objects>> 文档中,所有对象都是在同一个文档中,而在父-子关系文档中,父对象和子对象都是完全独立的文档。
95

10-
The parent-child functionality allows you to associate one document type with
11-
another, in a _one-to-many_ relationship--one parent to many children.((("one-to-many relationships"))) The
12-
advantages that parent-child has over <<nested-objects,`nested` objects>> are as follows:
6+
父-子关系的主要作用是允许把一个 type 的文档和另外一个 type 的文档关联起来,构成一对多的关系:一个父文档可以对应多个子文档 ((("one-to-many relationships"))) 。与 <<nested-objects,`nested` objects>> 相比,父-子关系的主要优势有:
137

14-
* The parent document can be updated without reindexing the children.
8+
* 更新父文档时,不会重新索引子文档。
9+
* 创建,修改或删除子文档时,不会影响父文档或其他子文档。这一点在这种场景下尤其有用:子文档数量较多,并且子文档创建和修改的频率高时。
10+
* 子文档可以作为搜索结果独立返回。
1511

16-
* Child documents can be added, changed, or deleted without affecting either
17-
the parent or other children. This is especially useful when child documents
18-
are large in number and need to be added or changed frequently.
19-
20-
* Child documents can be returned as the results of a search request.
21-
22-
Elasticsearch maintains a map of which parents are associated with
23-
which children. It is thanks to this map that query-time joins are fast, but
24-
it does place a limitation on the parent-child relationship: _the parent
25-
document and all of its children must live on the same shard_.
26-
27-
The parent-child ID maps are stored in <<docvalues>>, which allows them to execute
28-
quickly when fully hot in memory, but scalable enough to spill to disk when
29-
the map is very large.
12+
Elasticsearch 维护了一个父文档和子文档的映射关系,得益于这个映射,父-子文档关联查询操作非常快。但是这个映射也对父-子文档关系有个限制条件:父文档和其所有子文档,都必须要存储在同一个分片中。
3013

14+
父-子文档ID映射存储在 <<docvalues>> 中。当映射完全在内存中时, <<docvalues>> 提供对映射的快速处理能力,另一方面当映射非常大时,可以通过溢出到磁盘提供足够的扩展能力
3115

3216
[[parent-child-mapping]]
33-
=== Parent-Child Mapping
17+
=== 父-子关系文档映射
3418

35-
All that is needed in order to establish the parent-child relationship is to
36-
specify which document type should be the parent of a child type.((("mapping (types)", "parent-child")))((("parent-child relationship", "parent-child mapping"))) This must
37-
be done at index creation time, or with the `update-mapping` API before the
38-
child type has been created.
19+
建立父-子文档映射关系时只需要指定某一个文档 type 是另一个文档 type 的父亲。 ((("mapping (types)", "parent-child"))) ((("parent-child relationship", "parent-child mapping"))) 该关系可以在如下两个时间点设置:1)创建索引时;2)在子文档 type 创建之前更新父文档的 mapping。
3920

40-
As an example, let's say that we have a company that has branches in many
41-
cities. We would like to associate employees with the branch where they work.
42-
We need to be able to search for branches, individual employees, and employees
43-
who work for particular branches, so the nested model will not help. We
44-
could, of course,
45-
use <<application-joins,application-side-joins>> or
46-
<<denormalization,data denormalization>> here instead, but for demonstration
47-
purposes we will use parent-child.
21+
举例说明,有一个公司在多个城市有分公司,并且每一个分公司下面都有很多员工。有这样的需求:按照分公司、员工的维度去搜索,并且把员工和他们工作的分公司联系起来。针对该需求,用嵌套模型是无法实现的。当然,如果使用 <<application-joins,application-side-joins>> 或者 <<denormalization,data denormalization>> 也是可以实现的,但是为了演示的目的,在这里我们使用父-子文档。
4822

49-
All that we have to do is to tell Elasticsearch that the `employee` type has
50-
the `branch` document type as its `_parent`, which we can do when we create
51-
the index:
23+
我们需要告诉Elasticsearch,在创建员工 `employee` 文档 type 时,指定分公司 `branch` 的文档 type 为其父亲。
5224

5325
[source,json]
5426
-------------------------
@@ -64,4 +36,4 @@ PUT /company
6436
}
6537
}
6638
-------------------------
67-
<1> Documents of type `employee` are children of type `branch`.
39+
<1> `employee` 文档 是 `branch` 文档的子文档。

0 commit comments

Comments
 (0)