From 201f1cb38702b5e30a1a307baeb2640191ea9613 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 11 Sep 2016 16:57:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=AE=8C=E6=88=90Parent-Child=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E7=AB=A0=E7=9A=84=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../45_Indexing_parent_child.asciidoc | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/404_Parent_Child/45_Indexing_parent_child.asciidoc b/404_Parent_Child/45_Indexing_parent_child.asciidoc index 26fa7210a..aa02d197a 100644 --- a/404_Parent_Child/45_Indexing_parent_child.asciidoc +++ b/404_Parent_Child/45_Indexing_parent_child.asciidoc @@ -1,8 +1,7 @@ [[indexing-parent-child]] -=== Indexing Parents and Children +=== 构建父-子文档索引 -Indexing parent documents is no different from any other document. Parents -don't need to know anything about their children: +为父文档创建索引与为普通文档创建索引没有区别。父文档并不需要知道它有哪些子文档。 [source,json] ------------------------- @@ -15,8 +14,7 @@ POST /company/branch/_bulk { "name": "Champs Élysées", "city": "Paris", "country": "France" } ------------------------- -When indexing child documents, you must specify the ID of the associated -parent document: +创建子文档时,用户必须要通过 `parent` 参数来指定该子文档的父文档 ID: [source,json] ------------------------- @@ -27,31 +25,19 @@ PUT /company/employee/1?parent=london <1> "hobby": "hiking" } ------------------------- -<1> This `employee` document is a child of the `london` branch. +<1> 当前 `employee` 文档的父文档 ID 是 `london` 。 -This `parent` ID serves two purposes: it creates the link between the parent -and the child, and it ensures that the child document is stored on the same -shard as the parent. +父文档 ID 有两个作用:创建了父文档和子文档之间的关系,并且保证了父文档和子文档都在同一个分片上。 -In <>, we explained how Elasticsearch uses a routing value, -which defaults to the `_id` of the document, to decide which shard a document -should belong to. The routing value is plugged into this simple formula: +在 <> 中,我们解释了 Elasticsearch 如何通过对某一个值进行路由,来决定该文档属于哪一个分片,路由值默认为该文档的 `_id` 。分片路由的计算公式如下: shard = hash(routing) % number_of_primary_shards -However, if a `parent` ID is specified, it is used as the routing value -instead of the `_id`. In other words, both the parent and the child use the -same routing value--the `_id` of the parent--and so they are both stored -on the same shard. +如果指定了父文档的 ID,那么就会使用父文档的 ID 进行路由,而不会使用当前文档 `_id` 。也就是说,如果父文档和子文档都使用相同的值进行路由,那么父文档和子文档都会确定分布在同一个分片上。 -The `parent` ID needs to be specified on all single-document requests: -when retrieving a child document with a `GET` request, or when indexing, -updating, or deleting a child document. Unlike a search request, which is -forwarded to all shards in an index, these single-document requests are -forwarded only to the shard that holds the document--if the `parent` ID is -not specified, the request will probably be forwarded to the wrong shard. +在执行如下请求时需要知道父文档的 ID:通过 `GET` 请求获取一个子文档时;创建、更新或删除一个子文档时。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不知道父文档的 ID,那么很有可能会把请求发送到错误的分片上。 -The `parent` ID should also be specified when using the `bulk` API: +父文档的 ID 也可以在 `bulk` API 中指定 [source,json] ------------------------- @@ -64,8 +50,4 @@ POST /company/employee/_bulk { "name": "Adrien Grand", "dob": "1987-05-11", "hobby": "horses" } ------------------------- -WARNING: If you want to change the `parent` value of a child document, it is -not sufficient to just reindex or update the child document--the new parent -document may be on a different shard. Instead, you must first delete the old -child, and then index the new child. - +WARNING: 如果你想要改变一个子文档的 `parent` ,仅通过更新这个子文档是不够的,因为新的父文档有可能在另外一个分片上。因此,你必须要先把子文档删除,然后再重新索引这个文档。 From 48d133346c34ac702fc97ac19f0c896c618f8c9f Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 25 Sep 2016 17:49:54 +0800 Subject: [PATCH 2/5] revise acording pr first review --- 404_Parent_Child/45_Indexing_parent_child.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/404_Parent_Child/45_Indexing_parent_child.asciidoc b/404_Parent_Child/45_Indexing_parent_child.asciidoc index aa02d197a..515c8dc0c 100644 --- a/404_Parent_Child/45_Indexing_parent_child.asciidoc +++ b/404_Parent_Child/45_Indexing_parent_child.asciidoc @@ -29,15 +29,15 @@ PUT /company/employee/1?parent=london <1> 父文档 ID 有两个作用:创建了父文档和子文档之间的关系,并且保证了父文档和子文档都在同一个分片上。 -在 <> 中,我们解释了 Elasticsearch 如何通过对某一个值进行路由,来决定该文档属于哪一个分片,路由值默认为该文档的 `_id` 。分片路由的计算公式如下: +在 <> 中,我们解释了 Elasticsearch 如何通过路由值来决定该文档属于哪一个分片,路由值默认为该文档的 `_id` 。分片路由的计算公式如下: shard = hash(routing) % number_of_primary_shards 如果指定了父文档的 ID,那么就会使用父文档的 ID 进行路由,而不会使用当前文档 `_id` 。也就是说,如果父文档和子文档都使用相同的值进行路由,那么父文档和子文档都会确定分布在同一个分片上。 -在执行如下请求时需要知道父文档的 ID:通过 `GET` 请求获取一个子文档时;创建、更新或删除一个子文档时。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不知道父文档的 ID,那么很有可能会把请求发送到错误的分片上。 +在执行如下请求时需要指定父文档的 ID:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 -父文档的 ID 也可以在 `bulk` API 中指定 +父文档的 ID 应该在 `bulk` API 中指定 [source,json] ------------------------- @@ -50,4 +50,4 @@ POST /company/employee/_bulk { "name": "Adrien Grand", "dob": "1987-05-11", "hobby": "horses" } ------------------------- -WARNING: 如果你想要改变一个子文档的 `parent` ,仅通过更新这个子文档是不够的,因为新的父文档有可能在另外一个分片上。因此,你必须要先把子文档删除,然后再重新索引这个文档。 +WARNING: 如果你想要改变一个子文档的 `parent` 值,仅通过更新这个子文档是不够的,因为新的父文档有可能在另外一个分片上。因此,你必须要先把子文档删除,然后再重新索引这个子文档。 From eb7a59086fea30cac9bc6a4e9925176b5f0e697c Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 25 Sep 2016 17:51:56 +0800 Subject: [PATCH 3/5] revise pc --- 404_Parent_Child/45_Indexing_parent_child.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/45_Indexing_parent_child.asciidoc b/404_Parent_Child/45_Indexing_parent_child.asciidoc index 515c8dc0c..6fa4ad862 100644 --- a/404_Parent_Child/45_Indexing_parent_child.asciidoc +++ b/404_Parent_Child/45_Indexing_parent_child.asciidoc @@ -35,7 +35,7 @@ PUT /company/employee/1?parent=london <1> 如果指定了父文档的 ID,那么就会使用父文档的 ID 进行路由,而不会使用当前文档 `_id` 。也就是说,如果父文档和子文档都使用相同的值进行路由,那么父文档和子文档都会确定分布在同一个分片上。 -在执行如下请求时需要指定父文档的 ID:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 +在执行单文档的请求时需要指定父文档的 ID,包括:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 父文档的 ID 应该在 `bulk` API 中指定 From 7f6f8eaa0c688be23ec4f962fcd80c2674b3ca61 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 25 Sep 2016 17:53:25 +0800 Subject: [PATCH 4/5] add desc for single doc --- 404_Parent_Child/45_Indexing_parent_child.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/45_Indexing_parent_child.asciidoc b/404_Parent_Child/45_Indexing_parent_child.asciidoc index 6fa4ad862..4e1f251da 100644 --- a/404_Parent_Child/45_Indexing_parent_child.asciidoc +++ b/404_Parent_Child/45_Indexing_parent_child.asciidoc @@ -35,7 +35,7 @@ PUT /company/employee/1?parent=london <1> 如果指定了父文档的 ID,那么就会使用父文档的 ID 进行路由,而不会使用当前文档 `_id` 。也就是说,如果父文档和子文档都使用相同的值进行路由,那么父文档和子文档都会确定分布在同一个分片上。 -在执行单文档的请求时需要指定父文档的 ID,包括:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 +在执行单文档的请求时需要指定父文档的 ID,单文档请求包括:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 父文档的 ID 应该在 `bulk` API 中指定 From 8dc71b483639985e7c599dfb55f03cbee4e69346 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 25 Sep 2016 17:55:41 +0800 Subject: [PATCH 5/5] revise type --- 404_Parent_Child/45_Indexing_parent_child.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/45_Indexing_parent_child.asciidoc b/404_Parent_Child/45_Indexing_parent_child.asciidoc index 4e1f251da..9d6b9e15f 100644 --- a/404_Parent_Child/45_Indexing_parent_child.asciidoc +++ b/404_Parent_Child/45_Indexing_parent_child.asciidoc @@ -35,7 +35,7 @@ PUT /company/employee/1?parent=london <1> 如果指定了父文档的 ID,那么就会使用父文档的 ID 进行路由,而不会使用当前文档 `_id` 。也就是说,如果父文档和子文档都使用相同的值进行路由,那么父文档和子文档都会确定分布在同一个分片上。 -在执行单文档的请求时需要指定父文档的 ID,单文档请求包括:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时,如果不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 +在执行单文档的请求时需要指定父文档的 ID,单文档请求包括:通过 `GET` 请求获取一个子文档;创建、更新或删除一个子文档。而执行搜索请求时是不需要指定父文档的ID,这是因为搜索请求是向一个索引中的所有分片发起请求,而单文档的操作是只会向存储该文档的分片发送请求。因此,如果操作单个子文档时不指定父文档的 ID,那么很有可能会把请求发送到错误的分片上。 父文档的 ID 应该在 `bulk` API 中指定