AI Hints
Home›Elasticsearch Tutorial›Facets and Dashboards
Elasticsearch · Lesson 80 of 120

Pipeline Aggregations

Aggregations of aggregations.

⏱ 2 min read▶ Video at 1:15:24🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Revenue per month is nice. But which month was best? And what's the running total for the year? Pipeline aggregations work on the results of other aggregations.

  • Best month?
  • Running total?
  • Pipelines

Best month and running total

Date histogram makes monthly buckets, each with revenue. Cumulative sum adds a running total inside each bucket. Max bucket finds the month with the highest revenue. Run it. The best month, and its revenue.

Dev Tools Consoletext
GET orders/_search?filter_path=aggregations.best_month
{
  "size": 0,
  "aggs": {
    "months": {
      "date_histogram": { "field": "date", "calendar_interval": "month" },
      "aggs": {
        "revenue": { "sum": { "field": "total" } },
        "so_far":  { "cumulative_sum": { "buckets_path": "revenue" } } } },
    "best_month": { "max_bucket": { "buckets_path": "months>revenue" } }
  }
}
Output
{
  "aggregations": {
    "best_month": {
      "value": 57000.51,
      "keys": ["2026-04-01T00:00:00.000Z"]
    }
  }
}
Also uses _load
orders

Common pipelines

Cumulative sum gives running totals. Derivative gives the change from the last bucket. Moving function smooths a line. And max bucket, min bucket and avg bucket summarise across buckets. Buckets path points at the numbers to use.

keyvalue
cumulative_sumrunning total
derivativechange per bucket
moving_fnsmoothing
max/min/avg_bucketacross buckets

Summary

Pipeline aggregations calculate from other aggregations, using buckets path. Next, practise with a sales dashboard.

Key takeaways
  • buckets_path
  • cumulative_sum
  • max_bucket
Next up: Practice: A Sales Dashboard — one request, every number