Pipeline aggregations answer questions that require a second calculation over aggregation results. For example, daily cappuccino sales can become a running total, rather than remaining separate daily values. section 13.5
Unlike metric and bucket aggregations, which calculate from documents or group them into buckets, a pipeline aggregation consumes the output of another aggregation. section 13.0 section 13.6
Choose the pipeline type according to where its input aggregation sits:
- Parent pipelines work on a child aggregation and add resulting buckets or aggregations to the existing buckets. section 13.5.1
- Sibling pipelines calculate a new aggregation at the same level as the aggregations supplying their input. section 13.5.1
- Use buckets_path to identify the metric or bucket aggregation whose output feeds the pipeline. section 13.5.3
Running cappuccino sales total
After indexing coffee_sales data containing dates and product sales, place a cumulative_sum pipeline after the cappuccino_sales aggregation. The pipeline uses buckets_path to refer to cappuccino_sales, retaining the accumulated total for each successive day. Other useful choices include derivative for a histogram metric, moving_function for a sliding window, and max_bucket for the highest-valued bucket. section 13.5.2 section 13.5.3 section 13.5.4
Listing 13.21 Indexing data using the _bulk API
PUT coffee_sales/_bulk
{"index":{"_id":"1"}}
{"date":"2022-09-01","sales":{"cappuccino":23,"latte":12,"americano":9,
"tea":7},"price":{"cappuccino":2.50,"latte":2.40,"americano":2.10,
"tea":1.50}}
{"index":{"_id":"2"}}
{ "date":"2022-09-02","sales":{"cappuccino":40,"latte":16,"americano":19,
"tea":15},"price":{"cappuccino":2.50,"latte":2.40,"americano":2.10,
"tea":1.50}}
Inspect the coffee_sales documents used to demonstrate pipeline aggregation inputs. section 13.5.2
Table 13.1 Parent pipeline aggregations (view table figure)
Browse the available parent pipeline aggregations and their purposes. section 13.5.4
Table 13.2 Sibling pipeline aggregations (view table figure)
| Calculates the Kolmogorov–Smirnov statistic over a distribution |
|
Browse the available sibling pipeline aggregations and their purposes. section 13.5.4
