From bd1b80a12558b26e4f173f3ec310b89e13c2d6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Marcinkevi=C4=8Dius?= <marc.mantas@gmail.com> Date: Mon, 29 Aug 2016 10:39:28 +0300 Subject: [PATCH] added documentation --- docs/Aggregation/Pipeline/MinBucket.md | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/Aggregation/Pipeline/MinBucket.md diff --git a/docs/Aggregation/Pipeline/MinBucket.md b/docs/Aggregation/Pipeline/MinBucket.md new file mode 100644 index 0000000..9c33ccb --- /dev/null +++ b/docs/Aggregation/Pipeline/MinBucket.md @@ -0,0 +1,51 @@ +# Min Bucket Aggregation + +> More info about Min bucket aggregation is in the [official elasticsearch docs][1] + +A sibling pipeline aggregation which identifies the bucket(s) with the minimum value of a +specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). +The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. + +## Simple example + +```JSON +{ + "aggs" : { + "sales_per_month" : { + "date_histogram" : { + "field" : "date", + "interval" : "month" + }, + "aggs": { + "sales": { + "sum": { + "field": "price" + } + } + } + }, + "min_monthly_sales": { + "min_bucket": { + "buckets_path": "sales_per_month>sales" + } + } + } +} +``` + +And now the query via DSL: + +```php +$dateAggregation = new DateHistogramAggregation('sales_per_month', 'date', 'month'); +$sumAggregation = new SumAggregation('sales', 'price'); +$minBucketAggregation = new MinBucketAggregation('min_monthly_sales', 'sales_per_month>sales'); +$dateAggregation->addAggregation($sumAggregation); + +$search = new Search(); +$search->addAggregation($dateAggregation); +$search->addAggregation($minBucketAggregation); + +$queryArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-min-bucket-aggregation.html -- GitLab