Skip to content

Commit 9b68421

Browse files
weiqiangyuantangmisi
authored and
tangmisi
committed
chapter43_part3: /404_Parent_Child/50_Has_child.asciidoc (elasticsearch-cn#276)
* 完成Parent-Child第3部分的翻译 * revise according comment * revise according comment * revise according comment * revise according comment
1 parent cbd3630 commit 9b68421

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed
Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
[[has-child]]
2-
=== Finding Parents by Their Children
3-
4-
The `has_child` query and filter can be used to find parent documents based on
5-
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
6-
have employees born after 1980 with a query like this:
2+
=== 通过子文档查询父文档
73

4+
`has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80后员工所在的分公司:
85
[source,json]
96
-------------------------
107
GET /company/branch/_search
@@ -24,16 +21,10 @@ GET /company/branch/_search
2421
}
2522
-------------------------
2623

27-
Like the <<nested-query,`nested` query>>, the `has_child` query could
28-
match several child documents,((("has_child query and filter", "query"))) each with a different relevance
29-
score. How these scores are reduced to a single score for the parent document
30-
depends on the `score_mode` parameter. The default setting is `none`, which
31-
ignores the child scores and assigns a score of `1.0` to the parents, but it
32-
also accepts `avg`, `min`, `max`, and `sum`.
24+
类似于 <<nested-query,`nested` query>> ,`has_child` 查询可以匹配多个子文档((("has_child query and filter", "query"))),并且每一个子文档的评分都不同。但是由于每一个子文档都带有评分,这些评分如何规约成父文档的总得分取决于 `score_mode` 这个参数。该参数有多种取值策略:默认为 `none` ,会忽略子文档的评分,并且会给父文档评分设置为 `1.0` ;
25+
除此以外还可以设置成 `avg` 、 `min` 、 `max` 和 `sum` 。
3326

34-
The following query will return both `london` and `liverpool`, but `london`
35-
will get a better score because `Alice Smith` is a better match than
36-
`Barry Smith`:
27+
下面的查询将会同时返回 `london` 和 `liverpool` ,不过由于 `Alice Smith` 要比 `Barry Smith` 更加匹配查询条件,因此 `london` 会得到一个更高的评分。
3728

3829
[source,json]
3930
-------------------------
@@ -53,19 +44,14 @@ GET /company/branch/_search
5344
}
5445
-------------------------
5546

56-
TIP: The default `score_mode` of `none` is significantly faster than the other
57-
modes because Elasticsearch doesn't need to calculate the score for each child
58-
document. Set it to `avg`, `min`, `max`, or `sum` only if you care about the
59-
score.((("parent-child relationship", "finding parents by their children", "min_children and max_children")))
47+
TIP: `score_mode` 为默认的 `none` 时,会显著地比其模式要快,这是因为Elasticsearch不需要计算每一个子文档的评分。只有当你真正需要关心评分结果时,才需要为 `source_mode` 设值,例如设成 `avg` 、 `min` 、 `max` 或 `sum` 。((("parent-child relationship", "finding parents by their children", "min_children and max_children")))
6048

6149
[[min-max-children]]
62-
==== min_children and max_children
50+
==== min_children max_children
6351

64-
The `has_child` query and filter both accept the `min_children` and
65-
`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
66-
number of matching children is within the specified range.
52+
`has_child` 的查询和过滤都可以接受这两个参数:`min_children` 和 `max_children` 。 ((("min_children parameter")))((("max_children parameter")))((("has_child query and filter", "min_children or max_children parameters"))) 使用这两个参数时,只有当子文档数量在指定范围内时,才会返回父文档。
6753

68-
This query will match only branches that have at least two employees:
54+
如下查询只会返回至少有两个雇员的分公司:
6955

7056
[source,json]
7157
-------------------------
@@ -82,21 +68,14 @@ GET /company/branch/_search
8268
}
8369
}
8470
-------------------------
85-
<1> A branch must have at least two employees in order to match.
71+
<1> 至少有两个雇员的分公司才会符合查询条件。
8672

87-
The performance of a `has_child` query or filter with the `min_children` or
88-
`max_children` parameters is much the same as a `has_child` query with scoring
89-
enabled.
73+
带有 `min_children` 和 `max_children` 参数的 `has_child` 查询或过滤,和允许评分的 `has_child` 查询的性能非常接近。
9074

9175
.has_child Filter
9276
**************************
9377
94-
The `has_child` filter works((("has_child query and filter", "filter"))) in the same way as the `has_child` query, except
95-
that it doesn't support the `score_mode` parameter. It can be used only in
96-
_filter context_&#x2014;such as inside a `filtered` query--and behaves
97-
like any other filter: it includes or excludes, but doesn't score.
98-
99-
While the results of a `has_child` filter are not cached, the usual caching
100-
rules apply to the filter _inside_ the `has_child` filter.
78+
`has_child` 查询和过滤在运行机制上类似,((("has_child query and filter", "filter")))区别是 `has_child` 过滤不支持 `source_mode` 参数。`has_child` 过滤仅用于筛选内容--如内部的一个 `filtered` 查询--和其他过滤行为类似:包含或者排除,但没有进行评分。
10179
80+
`has_child` 过滤的结果没有被缓存,但是 `has_child` 过滤内部的过滤方法适用于通常的缓存规则。
10281
**************************

0 commit comments

Comments
 (0)