📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Elasticsearch Aggregations

Aggregations

6 min read Quiz at the end
Compute metrics (sum, avg, min, max) and group data with terms and date_histogram bucket aggregations.

Aggregations

# Metric aggregations
GET /orders/_search
{
  "size": 0,
  "aggs": {
    "total_revenue": { "sum":   { "field": "amount" } },
    "avg_order":     { "avg":   { "field": "amount" } },
    "min_order":     { "min":   { "field": "amount" } },
    "max_order":     { "max":   { "field": "amount" } },
    "order_count":   { "value_count": { "field": "id" } }
  }
}

# Bucket aggregation — group by field
GET /posts/_search
{
  "size": 0,
  "aggs": {
    "by_author": {
      "terms": { "field": "author", "size": 10 },
      "aggs": {
        "avg_price": { "avg": { "field": "price" } }
      }
    }
  }
}

# Date histogram
"aggs": { "by_month": { "date_histogram": {
    "field": "created_at", "calendar_interval": "month"
}}}
Topic Quiz · 1 questions

Test your understanding before moving on

1. What does setting size: 0 do in an Elasticsearch aggregation request?
💡 size: 0 skips returning the document hits — you only get the aggregation results.