We are working on updating this book for the latest version. Some content might be out of date.
Like the query DSL, aggregations have a composable syntax: independent units of functionality can be mixed and matched to provide the custom behavior that you need. This means that there are only a few basic concepts to learn, but nearly limitless combinations of those basic components.
To master aggregations, you need to understand only two main concepts:
- Collections of documents that meet a criterion
- Statistics calculated on the documents in a bucket
That’s it! Every aggregation is simply a combination of one or more buckets and zero or more metrics. To translate into rough SQL terms:
Buckets are conceptually similar to grouping in SQL, while metrics are similar
MAX(), and so forth.