Parent-child supports a
children
aggregation as
a direct analog to the nested
aggregation discussed in
Nested Aggregations. 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": {
"field": "country"
},
"aggs": {
"employees": {
"children": {
"type": "employee"
},
"aggs": {
"hobby": {
"terms": {
"field": "hobby"
}
}
}
}
}
}
}
}
|
The country field in the branch documents.
|
|
The children aggregation joins the parent documents with
their associated children of type employee .
|
|
The hobby field from the employee child documents.
|