Chapter 25. High-Level Concepts
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:
- Buckets
-
Collections of documents that meet a criterion
- Metrics
-
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:
SELECTCOUNT(color)![]()
FROMtableGROUPBYcolor
Buckets are conceptually similar to grouping in SQL, while metrics are similar
to COUNT(), SUM(), MAX(), and so forth.
Let’s dig into both of these concepts and see what they entail.
Buckets
A bucket is simply a collection of documents that meet a certain criteria:
-
An employee would land in either the male or female ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access