Children aggregation #
A single-bucket aggregation that scopes its sub-aggregations to the child documents of a relation field (parent-child joins). In a corpus where parents and children share an index, it is the lens that looks at the child side while the outer query talks about parents.
How it works #
Engine note: the current implementation runs sub-aggregations over the scoped document set keyed by the relation; it does not resolve per-parent child sets.
Concretely, the engine returns ONE bucket, keyed by the type name,
whose doc_count is the size of the current candidate set, with the
sub-aggregations executed over that same set. It does not walk the
relation to isolate actual child documents, and per-parent grouping
(one bucket per parent) is not available — full parent-child join
semantics need join support at the storage layer. Treat it as a
labelled scope for relation-oriented analysis, and pair it with the
traverse query when the graph
edges themselves matter.
Examples #
Articles carry a related_to relation; look at the relation’s child
side:
The response is a one-element buckets array carrying the relation
name as its key, with the sub-aggregations flattened inside:
{
...
"aggregations": {
"related": {
"buckets": [
{
"key": "related_to",
"doc_count": 44,
"top_tags": {
"buckets": [
{ "key": "optimizer", "doc_count": 2 },
{ "key": "search", "doc_count": 2 },
...
]
}
}
]
}
}
}
Use cases #
- Child-side rollups. Keep the outer query about the parent scope
while a nested
terms/sumreports child-shaped statistics under a clearly labelled bucket. - Relation health checks. A
value_countunder the bucket plus atraversewalk of the edges shows whether declared relations are actually populated. - Graph neighbourhood stats. On an edge-shaped corpus like
articles(related_toedges between 20 nodes), the bucket labels a scope whose sub-aggregations describe the documents carrying edges. - Migration scaffolding. Queries written against the ES shape parse and run, so porting an existing parent-child dashboard degrades to a scoped aggregate instead of failing outright.
Parameters for children
#
type
(Required, string) Name of the child relation to aggregate.aggs
(Optional, object) Sub-aggregations over the child documents.
Related #
nested— the nested-object counterpart, with full engine support- Relational field parameters
— declaring
references/relationfields in the schema - Traverse query — walking relation edges as a graph
- Join query — cross-collection semi-joins