From 33f963a50ca8daf5600f2dd5dba63265b8684da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Marcinkevi=C4=8Dius?= <marc.mantas@gmail.com> Date: Mon, 29 Aug 2016 13:50:51 +0300 Subject: [PATCH] added documentation --- docs/Aggregation/Pipeline/CumulativeSum.md | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 docs/Aggregation/Pipeline/CumulativeSum.md diff --git a/docs/Aggregation/Pipeline/CumulativeSum.md b/docs/Aggregation/Pipeline/CumulativeSum.md new file mode 100644 index 0000000..febd6fe --- /dev/null +++ b/docs/Aggregation/Pipeline/CumulativeSum.md @@ -0,0 +1,55 @@ +# Cumulative Sum Aggregation + +> More info about cumulative sum aggregation is in the [official elasticsearch docs][1] + +A parent pipeline aggregation which calculates the cumulative sum of a specified metric +in a parent histogram (or date_histogram) aggregation. The specified metric must be numeric +and the enclosing histogram must have min_doc_count set to 0 (default for histogram +aggregations). + +## Simple example + +```JSON +{ + "aggs" : { + "sales_per_month" : { + "date_histogram" : { + "field" : "date", + "interval" : "month" + }, + "aggs": { + "sales": { + "sum": { + "field": "price" + } + }, + "cumulative_sales": { + "cumulative_sum": { + "buckets_path": "sales" + } + } + } + } + } +} +``` + +And now the query via DSL: + +```php +$search = new Search(); + +$dateAggregation = new DateHistogramAggregation('sales_per_month', 'date', 'month'); +$dateAggregation->addAggregation( + new SumAggregation('sales', 'price') +); +$dateAggregation->addAggregation( + new CumulativeSumAggregation('cumulative_sales', 'sales') +); + +$search->addAggregation($dateAggregation); + +$aggArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-cumulative-sum-aggregation.html \ No newline at end of file -- GitLab