From 6950d2dc3f00856e7097ca9de07c41b6a2147e34 Mon Sep 17 00:00:00 2001 From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io> Date: Thu, 9 Jul 2015 10:06:16 +0300 Subject: [PATCH] Add filter aggregation doc. --- docs/Aggregation/Filter.md | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/Aggregation/Filter.md diff --git a/docs/Aggregation/Filter.md b/docs/Aggregation/Filter.md new file mode 100644 index 0000000..9a7a4d2 --- /dev/null +++ b/docs/Aggregation/Filter.md @@ -0,0 +1,39 @@ +# Filter Aggregation + +> More info about filter aggregation is in the [official elasticsearch docs][1] + +Defines a single bucket of all the documents in the current document set context that +match a specified filter. Often this will be used to narrow down the current aggregation +context to a specific set of documents. + +## Simple example + +```JSON +{ + "aggregations" : { + "agg_red_products" : { + "filter" : { "term": { "color": "red" } }, + "aggs" : { + "agg_avg_price" : { "avg" : { "field" : "price" } } + } + } + } +} +``` + +And now the query via DSL: + +```php +$termFilter = new TermFilter('color', 'red'); +$avgAggregation = new AvgAggregation('avg_price', 'price'); + +$filterAggregation = new FilterAggregation('grades_stats', $termFilter); +$filterAggregation->addAggregation($avgAggregation); + +$search = new Search(); +$search->addAggregation($filterAggregation); + +$queryArray = $search->toArray(); +``` + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html -- GitLab