Parent-child supports a
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?search_type=count
{
"aggs": {
"country": {
"terms": { (1)
"field": "country"
},
"aggs": {
"employees": {
"children": { (2)
"type": "employee"
},
"aggs": {
"hobby": {
"terms": { (3)
"field": "employee.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.