Skip to content

Latest commit

 

History

History
42 lines (39 loc) · 1.29 KB

60_Children_agg.asciidoc

File metadata and controls

42 lines (39 loc) · 1.29 KB

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:

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"
              }
            }
          }
        }
      }
    }
  }
}
  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.