WARNING: The 2.x versions of Elasticsearch have passed their EOL dates. If you are running a 2.x version, we strongly advise you to upgrade.
This documentation is no longer maintained and may be removed. For the latest information, see the current Elasticsearch documentation.
Combining the Twoedit
An aggregation is a combination of buckets and metrics. An aggregation may have a single bucket, or a single metric, or one of each. It may even have multiple buckets nested inside other buckets. For example, we can partition documents by which country they belong to (a bucket), and then calculate the average salary per country (a metric).
Because buckets can be nested, we can derive a much more complex aggregation:
- Partition documents by country (bucket).
- Then partition each country bucket by gender (bucket).
- Then partition each gender bucket by age ranges (bucket).
- Finally, calculate the average salary for each age range (metric)
This will give you the average salary per <country, gender, age>
combination. All in
one request and with one pass over the data!