Parent-child supports a
{ref}/search-aggregations-bucket-children-aggregation.html[children
aggregation] as a direct analog to the nested
aggregation discussed in
[nested-aggregation]. A parent aggregation (the equivalent of
reverse_nested
) is not supported.
This example demonstrates how we could determine the favorite hobbies of our employees by country:
GET /company/branch/_search
{
"size" : 0,
"aggs": {
"country": {
"terms": { (1)
"field": "country"
},
"aggs": {
"employees": {
"children": { (2)
"type": "employee"
},
"aggs": {
"hobby": {
"terms": { (3)
"field": "hobby"
}
}
}
}
}
}
}
}
-
The
country
field in thebranch
documents. -
The
children
aggregation joins the parent documents with their associated children of typeemployee
. -
The
hobby
field from theemployee
child documents.