You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
=== 通过子文档查询父文档
7
3
4
+
`has_child` 的查询和过滤可以通过子文档的内容来查询父文档。((("has_child query and filter")))((("parent-child relationship", "finding parents by their children")))例如,我们根据如下查询,可查出所有80后员工所在的分公司:
8
5
[source,json]
9
6
-------------------------
10
7
GET /company/branch/_search
@@ -24,16 +21,10 @@ GET /company/branch/_search
24
21
}
25
22
-------------------------
26
23
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
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")))
60
48
61
49
[[min-max-children]]
62
-
==== min_children and max_children
50
+
==== min_children 和 max_children
63
51
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"))) 使用这两个参数时,只有当子文档数量在指定范围内时,才会返回父文档。
67
53
68
-
This query will match only branches that have at least two employees:
54
+
如下查询只会返回至少有两个雇员的分公司:
69
55
70
56
[source,json]
71
57
-------------------------
@@ -82,21 +68,14 @@ GET /company/branch/_search
82
68
}
83
69
}
84
70
-------------------------
85
-
<1> A branch must have at least two employees in order to match.
71
+
<1> 至少有两个雇员的分公司才会符合查询条件。
86
72
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
0 commit comments