Reference · Cheat sheet

Aggregations

The compressed essence. Print it, pin it.

From lesson 0007See also glossary

Three families

FamilyDoesExamples
metrica value over the docsavg, sum, min, max, stats, cardinality
bucketgroup docs into buckets (each has doc_count)terms, range, histogram, date_histogram
pipelineinput from other aggs, not docsavg_bucket, derivative

Rules

Shape: group then measure

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