GET /company/branch/_search
{
  "size" : 0,
  "aggs": {
    "country": {
      "terms": { (1)
        "field": "country"
      },
      "aggs": {
        "employees": {
          "children": { (2)
            "type": "employee"
          },
          "aggs": {
            "hobby": {
              "terms": { (3)
                "field": "hobby"
              }
            }
          }
        }
      }
    }
  }
}Children Aggregation
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:
- 
The countryfield in thebranchdocuments.
- 
The childrenaggregation joins the parent documents with their associated children of typeemployee.
- 
The hobbyfield from theemployeechild documents.