Skip to content

Latest commit

 

History

History
43 lines (40 loc) · 1.22 KB

60_Children_agg.asciidoc

File metadata and controls

43 lines (40 loc) · 1.22 KB

Children Aggregation

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"
              }
            }
          }
        }
      }
    }
  }
}
  1. The country field in the branch documents.

  2. The children aggregation joins the parent documents with their associated children of type employee.

  3. The hobby field from the employee child documents.