Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What are pipeline aggregations in Elasticsearch?

Elasticsearch
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 6, 2026
7 min read

Pipeline aggregations in Elasticsearch work on the output of other aggregations instead of on documents. They take the buckets or metric values that a parent or sibling aggregation produced and compute something new from them, such as a running total, a rate of change or the highest monthly sum. The keyword for this guide is elasticsearch pipeline aggregation, and the examples target Elasticsearch 8 and 9.

You use them when a question cannot be answered from raw documents alone, for example "which month had the highest revenue?" or "how much did sales change from one month to the next?".

Table of Contents

  • How pipeline aggregations differ from metric and bucket aggregations
  • Understanding buckets_path
  • Parent pipelines on a date histogram
    • Smoothing with moving_fn
    • Computing per-bucket values with bucket_script
    • Filtering and sorting buckets
  • Sibling pipelines for whole-series answers
  • Pitfalls and limits
  • Frequently Asked Questions
    • Do pipeline aggregations read documents?
    • What is the difference between a parent and a sibling pipeline?
    • How do I get a moving average now that moving_avg is gone?
    • How do I handle empty months?
  • Summary
  • Related Articles

How pipeline aggregations differ from metric and bucket aggregations

Metric aggregations such as sum and avg compute a number from document fields. Bucket aggregations such as terms and date_histogram group documents. Pipeline aggregations run after those and read their results through a buckets_path. They never see documents.

There are two families.

FamilyWhere it sitsWhat it doesExamples
ParentInside the multi-bucket aggregationAdds a value to each existing bucketderivative, cumulative_sum, moving_fn, bucket_script, bucket_selector, bucket_sort
SiblingNext to the aggregation it readsProduces one new value for the whole set of bucketsavg_bucket, sum_bucket, min_bucket, max_bucket, stats_bucket, percentiles_bucket

Understanding buckets_path

Every pipeline aggregation needs a buckets_path that points at the value to read. The path uses the aggregation names, separated by > for nesting and . for a metric property.

  • revenue refers to a sibling metric named revenue in the same bucket.
  • sales_per_month>revenue refers to the revenue metric inside each bucket of sales_per_month.
  • the_percentile[99.9] or stats.max reads one value out of a multi-value metric.
  • The special path _count reads the document count of a bucket.

A wrong path produces an error that names the missing aggregation, so start by checking the spelling.

Parent pipelines on a date histogram

The most common pattern is a monthly histogram with a metric, followed by a parent pipeline.

json

Each monthly bucket now has three values: the month's revenue, the difference from the previous month (revenue_change), and the total so far (running_revenue). The first bucket has no revenue_change, because there is no earlier bucket to subtract.

A derivative needs buckets that are contiguous. If a month has no documents it simply has no bucket unless you set min_doc_count: 0, and a gap makes the derivative compare the wrong periods. Use gap_policy to decide what happens: skip (the default) ignores empty buckets and insert_zeros treats them as zero.

Smoothing with moving_fn

moving_fn applies a script over a sliding window of earlier values. This gives a moving average.

json

The MovingFunctions helper includes min, max, sum, unweightedAvg, linearWeightedAvg, ewma and holt. It replaced the older moving_avg aggregation, which was removed in Elasticsearch 8.0 (it had been deprecated since 6.4).

Computing per-bucket values with bucket_script

bucket_script runs a script over several metrics of the same bucket.

json

Here the variables rev and orders come from the paths, and the script returns the average order value of each month. Guard against a division by zero when a bucket can be empty.

Filtering and sorting buckets

bucket_selector drops buckets that fail a condition, and bucket_sort sorts or truncates the buckets of its parent.

json

bucket_sort is the way to sort a terms aggregation by a pipeline-derived value, which terms ordering cannot do by itself.

Sibling pipelines for whole-series answers

A sibling pipeline sits at the same level as the aggregation it summarises and returns one value.

json
text

max_bucket returns the value and the key of the winning bucket, which is how you find the month and not only the number. Other siblings include sum_bucket, min_bucket, stats_bucket, extended_stats_bucket and percentiles_bucket.

Pitfalls and limits

  • Pipeline aggregations run on the coordinating node after the shards respond, so they only see buckets that the shards returned. Combined with a terms aggregation that has a small size, results can be incomplete.
  • They cannot be a parent of other aggregations; a pipeline aggregation has no sub-aggregations.
  • A bucket path must point to a numeric value. Pointing at a bucket aggregation with no metric raises an error.
  • Scripts add CPU cost per bucket, so keep the bucket count modest.
  • Time series with date_histogram over large ranges can hit the search.max_buckets limit before the pipeline runs.

Frequently Asked Questions

Do pipeline aggregations read documents?

No. They read the results of other aggregations through buckets_path. If you need document-level data, use a metric aggregation first and pipe its result.

What is the difference between a parent and a sibling pipeline?

A parent pipeline lives inside a multi-bucket aggregation and adds a value to each bucket. A sibling pipeline lives next to the aggregation and returns one value for the whole set.

How do I get a moving average now that moving_avg is gone?

Use moving_fn with a built-in function such as MovingFunctions.unweightedAvg(values) or ewma.

How do I handle empty months?

Set min_doc_count: 0 on the histogram so the buckets exist, and pick a gap_policy that matches how a missing value should be treated.

Summary

Pipeline aggregations compute on aggregation results. Parent pipelines such as derivative, cumulative_sum, moving_fn and bucket_script add a value per bucket, while sibling pipelines such as max_bucket and avg_bucket return one summary for the series. Point them at the right data with buckets_path, mind gaps in a date histogram, and remember that they only see the buckets that the previous stage produced.

Related Articles

  • How do you page through buckets with composite aggregation?
  • How does BM25 relevance scoring work in Elasticsearch?
  • Learn Elasticsearch: Complete Study Roadmap, Beginner to Advanced
Share

Similar posts

  • How do you page through buckets with composite aggregation?
  • Elasticsearch Cardinality Aggregation: Count Unique Values
  • How to Nest Sub-Aggregations in Elasticsearch (With Examples)
  • Elasticsearch date_histogram Aggregation for Time Series
  • Elasticsearch Terms Aggregation: Group Documents by Field Value
  • Elasticsearch Metric Aggregations: avg, sum, min, max and stats
  • What Are Aggregations in Elasticsearch? Metrics, Buckets, Pipelines
  • How do you highlight matches in Elasticsearch results?