From 06458e762307234562091010c1cb331625487aa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Marcinkevi=C4=8Dius?= <marc.mantas@gmail.com> Date: Mon, 29 Aug 2016 14:46:57 +0300 Subject: [PATCH] added documentation --- docs/Aggregation/Pipeline/BucketSelector.md | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/Aggregation/Pipeline/BucketSelector.md diff --git a/docs/Aggregation/Pipeline/BucketSelector.md b/docs/Aggregation/Pipeline/BucketSelector.md new file mode 100644 index 0000000..c206102 --- /dev/null +++ b/docs/Aggregation/Pipeline/BucketSelector.md @@ -0,0 +1,62 @@ +# Bucket Selector Aggregation + +> More info bucket selector aggregation is in the [official elasticsearch docs][1] + +A parent pipeline aggregation which executes a script which determines whether the +current bucket will be retained in the parent multi-bucket aggregation. The specified +metric must be numeric and the script must return a boolean value. If the script +language is expression then a numeric return value is permitted. In this case 0.0 will +be evaluated as false and all other values will evaluate to true. + +## Simple example + +```JSON +{ + "aggs" : { + "sales_per_month" : { + "date_histogram" : { + "field" : "date", + "interval" : "month" + }, + "aggs": { + "total_sales": { + "sum": { + "field": "price" + } + }, + "sales_bucket_filter": { + "bucket_selector": { + "buckets_path": { + "totalSales": "total_sales" + }, + "script": "totalSales <= 50" + } + } + } + } + } +} +``` + +And now the query via DSL: + +```php +$search = new Search(); + +$dateAggregation = new DateHistogramAggregation('sales_per_month', 'date', 'month'); +$dateAggregation->addAggregation( + new SumAggregation('total_sales', 'price'); +); +$scriptAggregation = new BucketSelectorAggregation( + 'sales_bucket_filter', + ['totalSales' => 'total_sales'] +); +$scriptAggregation->setScript('totalSales <= 50'); +$dateAggregation->addAggregation($scriptAggregation); + +$search->addAggregation($dateAggregation); + +$aggArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-selector-aggregation.html \ No newline at end of file -- GitLab