From 32ed2b64d82f9e86112974025426f22045f045a4 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Sun, 11 Sep 2016 18:10:20 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=AE=8C=E6=88=90Parent-Child=E7=AC=AC3?= =?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/50_Has_child.asciidoc | 47 +++++++------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/404_Parent_Child/50_Has_child.asciidoc b/404_Parent_Child/50_Has_child.asciidoc index b448b202a..a6dd4c2f3 100644 --- a/404_Parent_Child/50_Has_child.asciidoc +++ b/404_Parent_Child/50_Has_child.asciidoc @@ -1,10 +1,7 @@ [[has-child]] -=== Finding Parents by Their Children - -The `has_child` query and filter can be used to find parent documents based on -the contents of their children.((("has_child query and filter")))((("parent-child relationship", "finding parents by their children"))) For instance, we could find all branches that -have employees born after 1980 with a query like this: +=== 根据子文档查询父文档 +`has_child` 的 query 和 filter 可以根据子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有出生在1980年之后的雇员所在的公司: [source,json] ------------------------- GET /company/branch/_search @@ -24,16 +21,10 @@ GET /company/branch/_search } ------------------------- -Like the <>, the `has_child` query could -match several child documents,((("has_child query and filter", "query"))) each with a different relevance -score. How these scores are reduced to a single score for the parent document -depends on the `score_mode` parameter. The default setting is `none`, which -ignores the child scores and assigns a score of `1.0` to the parents, but it -also accepts `avg`, `min`, `max`, and `sum`. +`has_child` query 和 <> 类似,查询返回的结果都可以包括多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分值都不同。但是由于每一个子文档都带有评分,因此父文档的评分需要取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ; +还可以设置成 `avg` 、 `min` 、 `max` 和 `sum` 。 -The following query will return both `london` and `liverpool`, but `london` -will get a better score because `Alice Smith` is a better match than -`Barry Smith`: +下面的查询将会返回 `london` 和 `liverpool` 。由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。 [source,json] ------------------------- @@ -53,19 +44,14 @@ GET /company/branch/_search } ------------------------- -TIP: The default `score_mode` of `none` is significantly faster than the other -modes because Elasticsearch doesn't need to calculate the score for each child -document. Set it to `avg`, `min`, `max`, or `sum` only if you care about the -score.((("parent-child relationship", "finding parents by their children", "min_children and max_children"))) +TIP: `score_mode` 为默认的 `none` 时,会显著地比其模式要快,这是因为Elasticsearch不需要计算每一个子文档的评分。只有当你真正需要关心评分结果时,才需要为 `source_mode` 设值,例如设成 `avg` 、 `min` 、 `max` 或 `sum` 。((("parent-child relationship", "finding parents by their children", "min_children and max_children"))) [[min-max-children]] -==== min_children and max_children +==== min_children 和 max_children -The `has_child` query and filter both accept the `min_children` and -`max_children` parameters,((("min_children parameter")))((("max_children parameter")))((("has_child query and filter", "min_children or max_children parameters"))) which will return the parent document only if the -number of matching children is within the specified range. +`has_child` 的 query 和 filter 都可以传这两个参数:`min_children` 和 `max_children` 。 ((("min_children parameter")))((("max_children parameter")))((("has_child query and filter", "min_children or max_children parameters"))) 使用这两个参数时,只有当父文档的子文档数量大于 `min_children` 或者小于 `max_children` 时,才会返回父文档。 -This query will match only branches that have at least two employees: +如下查询只会返回至少有两个雇员的分公司: [source,json] ------------------------- @@ -82,21 +68,14 @@ GET /company/branch/_search } } ------------------------- -<1> A branch must have at least two employees in order to match. +<1> 至少有两个雇员的分公司才会符合查询条件。 -The performance of a `has_child` query or filter with the `min_children` or -`max_children` parameters is much the same as a `has_child` query with scoring -enabled. +带有 `has_child` 、 `min_children` 和 `max_children` 参数的 query 或者 filter,在性能上都没有显著差异。 .has_child Filter ************************** -The `has_child` filter works((("has_child query and filter", "filter"))) in the same way as the `has_child` query, except -that it doesn't support the `score_mode` parameter. It can be used only in -_filter context_—such as inside a `filtered` query--and behaves -like any other filter: it includes or excludes, but doesn't score. - -While the results of a `has_child` filter are not cached, the usual caching -rules apply to the filter _inside_ the `has_child` filter. +`has_child` filter 和 `has_child` query 在运行机制上类似,((("has_child query and filter", "filter")))区别是 `has_child` filter 不支持 `source_mode` 参数。`has_child` filter 只可以用在 filter 的上下文中(例如在 `filtered` query 中)并且和其他任何的 filter 一样:结果存在,或者不存在,并且没有评分机制。 +`has_child` filter 本身的结果不可被缓存,但是其内部 filter 的结果是可以被缓存的。 ************************** From 0abcb8e90897740df99104171468d7bfea8fc6af Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 00:20:24 +0800 Subject: [PATCH 2/5] revise according comment --- 404_Parent_Child/50_Has_child.asciidoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/404_Parent_Child/50_Has_child.asciidoc b/404_Parent_Child/50_Has_child.asciidoc index a6dd4c2f3..6ab6d23c6 100644 --- a/404_Parent_Child/50_Has_child.asciidoc +++ b/404_Parent_Child/50_Has_child.asciidoc @@ -1,7 +1,7 @@ [[has-child]] === 根据子文档查询父文档 -`has_child` 的 query 和 filter 可以根据子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有出生在1980年之后的雇员所在的公司: +`has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80员工所在的分公司: [source,json] ------------------------- GET /company/branch/_search @@ -21,10 +21,10 @@ GET /company/branch/_search } ------------------------- -`has_child` query 和 <> 类似,查询返回的结果都可以包括多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分值都不同。但是由于每一个子文档都带有评分,因此父文档的评分需要取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ; -还可以设置成 `avg` 、 `min` 、 `max` 和 `sum` 。 +类似于 <> 类似,`has_child` 查询可以匹配多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分都不同。但是由于每一个子文档都带有评分,这些评分如何规约成父文档的总得分取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ; +除此以外还可以设置成 `avg` 、 `min` 、 `max` 和 `sum` 。 -下面的查询将会返回 `london` 和 `liverpool` 。由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。 +下面的查询将会同时返回 `london` 和 `liverpool` ,由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。 [source,json] ------------------------- @@ -49,7 +49,7 @@ TIP: `score_mode` 为默认的 `none` 时,会显著地比其模式要快,这 [[min-max-children]] ==== min_children 和 max_children -`has_child` 的 query 和 filter 都可以传这两个参数:`min_children` 和 `max_children` 。 ((("min_children parameter")))((("max_children parameter")))((("has_child query and filter", "min_children or max_children parameters"))) 使用这两个参数时,只有当父文档的子文档数量大于 `min_children` 或者小于 `max_children` 时,才会返回父文档。 +`has_child` 的查询和过滤都可以接受这两个参数:`min_children` 和 `max_children` 。 ((("min_children parameter")))((("max_children parameter")))((("has_child query and filter", "min_children or max_children parameters"))) 使用这两个参数时,只有当子文档数量在指定范围内时,才会返回父文档。 如下查询只会返回至少有两个雇员的分公司: @@ -70,12 +70,12 @@ GET /company/branch/_search ------------------------- <1> 至少有两个雇员的分公司才会符合查询条件。 -带有 `has_child` 、 `min_children` 和 `max_children` 参数的 query 或者 filter,在性能上都没有显著差异。 +带有 `min_children` 和 `max_children` 参数的 `has_child` 查询或过滤,和允许评分的 `has_child` 查询性能非常接近。 .has_child Filter ************************** -`has_child` filter 和 `has_child` query 在运行机制上类似,((("has_child query and filter", "filter")))区别是 `has_child` filter 不支持 `source_mode` 参数。`has_child` filter 只可以用在 filter 的上下文中(例如在 `filtered` query 中)并且和其他任何的 filter 一样:结果存在,或者不存在,并且没有评分机制。 +`has_child` 查询和过滤在运行机制上类似,((("has_child query and filter", "filter")))区别是 `has_child` 过滤不支持 `source_mode` 参数。`has_child` 过滤仅用于筛选内容--如内部的一个 `filtered` 查询--和其他过滤行为类似:包含或者排除,但没有进行评分。 -`has_child` filter 本身的结果不可被缓存,但是其内部 filter 的结果是可以被缓存的。 +`has_child` 过滤的结果没有被缓存,但是 `has_child` 过滤内部 的过滤方法适用于通常的缓存规则。 ************************** From 20404cb4fb3d69e86140e82205d440783def2dcf Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 00:21:24 +0800 Subject: [PATCH 3/5] revise according comment --- 404_Parent_Child/50_Has_child.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404_Parent_Child/50_Has_child.asciidoc b/404_Parent_Child/50_Has_child.asciidoc index 6ab6d23c6..99f68f463 100644 --- a/404_Parent_Child/50_Has_child.asciidoc +++ b/404_Parent_Child/50_Has_child.asciidoc @@ -1,5 +1,5 @@ [[has-child]] -=== 根据子文档查询父文档 +=== 通过子文档查询父文档 `has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80员工所在的分公司: [source,json] From 84462d064fd8ec28ebd33b37de3e19aa3ab58fd7 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 00:25:43 +0800 Subject: [PATCH 4/5] revise according comment --- 404_Parent_Child/50_Has_child.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/404_Parent_Child/50_Has_child.asciidoc b/404_Parent_Child/50_Has_child.asciidoc index 99f68f463..9187f5ba4 100644 --- a/404_Parent_Child/50_Has_child.asciidoc +++ b/404_Parent_Child/50_Has_child.asciidoc @@ -1,7 +1,7 @@ [[has-child]] === 通过子文档查询父文档 -`has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80员工所在的分公司: +`has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80后员工所在的分公司: [source,json] ------------------------- GET /company/branch/_search @@ -21,10 +21,10 @@ GET /company/branch/_search } ------------------------- -类似于 <> 类似,`has_child` 查询可以匹配多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分都不同。但是由于每一个子文档都带有评分,这些评分如何规约成父文档的总得分取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ; +类似于 <> ,`has_child` 查询可以匹配多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分都不同。但是由于每一个子文档都带有评分,这些评分如何规约成父文档的总得分取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ; 除此以外还可以设置成 `avg` 、 `min` 、 `max` 和 `sum` 。 -下面的查询将会同时返回 `london` 和 `liverpool` ,由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。 +下面的查询将会同时返回 `london` 和 `liverpool` ,不过由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。 [source,json] ------------------------- From 9ffae8f9ece18e571c425588293726ec0e10fe38 Mon Sep 17 00:00:00 2001 From: "weiqiang.yuan" Date: Wed, 19 Oct 2016 00:28:54 +0800 Subject: [PATCH 5/5] revise according comment --- 404_Parent_Child/50_Has_child.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/404_Parent_Child/50_Has_child.asciidoc b/404_Parent_Child/50_Has_child.asciidoc index 9187f5ba4..eb01e36f6 100644 --- a/404_Parent_Child/50_Has_child.asciidoc +++ b/404_Parent_Child/50_Has_child.asciidoc @@ -70,12 +70,12 @@ GET /company/branch/_search ------------------------- <1> 至少有两个雇员的分公司才会符合查询条件。 -带有 `min_children` 和 `max_children` 参数的 `has_child` 查询或过滤,和允许评分的 `has_child` 查询性能非常接近。 +带有 `min_children` 和 `max_children` 参数的 `has_child` 查询或过滤,和允许评分的 `has_child` 查询的性能非常接近。 .has_child Filter ************************** `has_child` 查询和过滤在运行机制上类似,((("has_child query and filter", "filter")))区别是 `has_child` 过滤不支持 `source_mode` 参数。`has_child` 过滤仅用于筛选内容--如内部的一个 `filtered` 查询--和其他过滤行为类似:包含或者排除,但没有进行评分。 -`has_child` 过滤的结果没有被缓存,但是 `has_child` 过滤内部 的过滤方法适用于通常的缓存规则。 +`has_child` 过滤的结果没有被缓存,但是 `has_child` 过滤内部的过滤方法适用于通常的缓存规则。 **************************