-
Aivaras Gotovskis authoredAivaras Gotovskis authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Filter.md 1.06 KiB
Filter Aggregation
More info about filter aggregation is in the official elasticsearch docs
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
{
"aggregations" : {
"agg_red_products" : {
"filter" : { "term": { "color": "red" } },
"aggs" : {
"agg_avg_price" : { "avg" : { "field" : "price" } }
}
}
}
}
And now the query via DSL:
$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();