From a3f4ba98a4101062a9d6827d0e7c91ee19dcbe6a Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 11 Sep 2016 18:19:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=8C=E6=88=90Parent-Child=E7=AC=AC4?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404_Parent_Child/55_Has_parent.asciidoc | 27 ++++++++----------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/404_Parent_Child/55_Has_parent.asciidoc b/404_Parent_Child/55_Has_parent.asciidoc index fcc37e404..4b6902c76 100644 --- a/404_Parent_Child/55_Has_parent.asciidoc +++ b/404_Parent_Child/55_Has_parent.asciidoc @@ -1,14 +1,9 @@ [[has-parent]] -=== Finding Children by Their Parents +=== 根据父文档查询子文档 -While a `nested` query can always ((("parent-child relationship", "finding children by their parents")))return only the root document as a result, -parent and child documents are independent and each can be queried -independently. The `has_child` query allows us to return parents based on -data in their children, and the `has_parent` query returns children based on -data in their parents.((("has_parent query and filter", "query"))) +`nested` query 只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),而在父-子文档中,父文档和子文档都是独立的,并且可以被单独地查询出来。`has_child` 实现了根据子文档的数据内容来查询父文档,类似我们也有 `has_parent` ,实现了根据父文档的数据内容来查询子文档((("has_parent query and filter", "query")))。 -It looks very similar to the `has_child` query. This example returns -employees who work in the UK: +`has_parent` 和 `has_child` 非常相似,下面的查询将会返回所有在 UK 工作的雇员: [source,json] ------------------------- @@ -26,19 +21,13 @@ GET /company/employee/_search } } ------------------------- -<1> Returns children who have parents of type `branch` +<1> 指定子文档对应的父文档 type 是 `branch` -The `has_parent` query also supports the `score_mode`,((("score_mode parameter"))) but it accepts only two -settings: `none` (the default) and `score`. Each child can have only one -parent, so there is no need to reduce multiple scores into a single score for -the child. The choice is simply between using the score (`score`) or not -(`none`). +`has_parent` query 也支持 `score_mode` 这个参数,((("score_mode parameter")))但是该参数只支持两种值: `none` (默认)和 `score` 。因为每一个子文档都只有一个父文档,对子文档而言并不需要在多个评分中进行筛选,因此 `score_mode` 就很简单,取值仅为 `score` 和 `none` 。 -.Non-scoring has_parent Query +.不带评分的 has_parent 查询 ************************** -When used in non-scoring mode (e.g. inside a `filter` clause), the `has_parent` -query no longer supports the `score_mode` parameter. Because it is merely -including/excluding documents and not scoring, the `score_mode` parameter -no longer applies. +当不需要评分时(例如:在一个 `filter` 查询语句中),`has_parent` 不支持 `source_mode` 参数。因为 filter 查询的结果仅是存在或者不存在并且不需要评分,因此 `source_mode` 这个参数也就不需要了。 + ************************** From b5650e5b0a806c660e323bf41ad75f0476c11334 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 01:00:37 +0800 Subject: [PATCH 2/4] revise according comment --- 404_Parent_Child/55_Has_parent.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/404_Parent_Child/55_Has_parent.asciidoc b/404_Parent_Child/55_Has_parent.asciidoc index 4b6902c76..6744da891 100644 --- a/404_Parent_Child/55_Has_parent.asciidoc +++ b/404_Parent_Child/55_Has_parent.asciidoc @@ -1,7 +1,7 @@ [[has-parent]] === 根据父文档查询子文档 -`nested` query 只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),而在父-子文档中,父文档和子文档都是独立的,并且可以被单独地查询出来。`has_child` 实现了根据子文档的数据内容来查询父文档,类似我们也有 `has_parent` ,实现了根据父文档的数据内容来查询子文档((("has_parent query and filter", "query")))。 +虽然 `nested` 查询只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),但是父文档和子文档本身是彼此独立并且可被单独查询的。我们使用 `has_child` 语句可以基于子文档来查询父文档,使用 `has_parent` 语句可以基于子文档来查询父文档。。 `has_parent` 和 `has_child` 非常相似,下面的查询将会返回所有在 UK 工作的雇员: @@ -21,13 +21,13 @@ GET /company/employee/_search } } ------------------------- -<1> 指定子文档对应的父文档 type 是 `branch` +<1> 返回父文档 `type` 是 `branch` 的所有子文档 -`has_parent` query 也支持 `score_mode` 这个参数,((("score_mode parameter")))但是该参数只支持两种值: `none` (默认)和 `score` 。因为每一个子文档都只有一个父文档,对子文档而言并不需要在多个评分中进行筛选,因此 `score_mode` 就很简单,取值仅为 `score` 和 `none` 。 +`has_parent` 查询也支持 `score_mode` 这个参数,((("score_mode parameter")))但是该参数只支持两种值: `none` (默认)和 `score` 。每个子文档都只有一个父文档,因此这里不存在将多个评分规约为一个的情况, `score_mode` 的取值仅为 `score` 和 `none` 。 .不带评分的 has_parent 查询 ************************** -当不需要评分时(例如:在一个 `filter` 查询语句中),`has_parent` 不支持 `source_mode` 参数。因为 filter 查询的结果仅是存在或者不存在并且不需要评分,因此 `source_mode` 这个参数也就不需要了。 +当 `has_parent` 查询用于非评分模式(比如 filter 查询语句)时, `score_mode` 参数就不再起作用了。因为这种模式只是简单地包含或排除文档,没有评分,那么 `score_mode` 参数也就没有意义了。 ************************** From 6e816d3581e5e0d1a602a313b6e283e19284e97c Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 01:01:46 +0800 Subject: [PATCH 3/4] revise according comment --- 404_Parent_Child/55_Has_parent.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/55_Has_parent.asciidoc b/404_Parent_Child/55_Has_parent.asciidoc index 6744da891..6ddcc2428 100644 --- a/404_Parent_Child/55_Has_parent.asciidoc +++ b/404_Parent_Child/55_Has_parent.asciidoc @@ -1,5 +1,5 @@ [[has-parent]] -=== 根据父文档查询子文档 +=== 通过父文档查询子文档 虽然 `nested` 查询只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),但是父文档和子文档本身是彼此独立并且可被单独查询的。我们使用 `has_child` 语句可以基于子文档来查询父文档,使用 `has_parent` 语句可以基于子文档来查询父文档。。 From bde0825464a38f2c9b1349c4bc36f50f73b95e21 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sat, 22 Oct 2016 14:29:38 +0800 Subject: [PATCH 4/4] save --- 404_Parent_Child/55_Has_parent.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/55_Has_parent.asciidoc b/404_Parent_Child/55_Has_parent.asciidoc index 6ddcc2428..d616e2d17 100644 --- a/404_Parent_Child/55_Has_parent.asciidoc +++ b/404_Parent_Child/55_Has_parent.asciidoc @@ -1,7 +1,7 @@ [[has-parent]] === 通过父文档查询子文档 -虽然 `nested` 查询只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),但是父文档和子文档本身是彼此独立并且可被单独查询的。我们使用 `has_child` 语句可以基于子文档来查询父文档,使用 `has_parent` 语句可以基于子文档来查询父文档。。 +虽然 `nested` 查询只能返回最顶层的文档 ((("parent-child relationship", "finding children by their parents"))),但是父文档和子文档本身是彼此独立并且可被单独查询的。我们使用 `has_child` 语句可以基于子文档来查询父文档,使用 `has_parent` 语句可以基于子文档来查询父文档。 ((("has_parent query and filter", "query"))) `has_parent` 和 `has_child` 非常相似,下面的查询将会返回所有在 UK 工作的雇员: