Reference · Cheat sheet
The compressed essence. Print it, pin it.
| Family | Does | Examples |
|---|---|---|
| metric | a value over the docs | avg, sum, min, max, stats, cardinality |
| bucket | group docs into buckets (each has doc_count) | terms, range, histogram, date_histogram |
| pipeline | input from other aggs, not docs | avg_bucket, derivative |
query-matched docs. No query → whole index. Combine with bool to summarize a filtered subset."size": 0 to drop hits and return aggregations only.aggs → per-bucket metrics / sub-buckets.keyword, not text (text is tokenized; disabled unless costly fielddata).terms counts are approximate across shards — check doc_count_error_upper_bound and sum_other_doc_count. Default size = 10.GET /idx/_search
{
"size": 0,
"query": { "bool": { "filter": { "range": { "year": { "gte": 2020 } } } } },
"aggs": {
"by_status": { // bucket
"terms": { "field": "status" },
"aggs": {
"avg_views": { "avg": { "field": "views" } } // metric per bucket
}
}
}
}
← lesson 0007 · Source: Aggregations reference