You need to sign in or sign up before continuing.
-
Mantas Marcinkevičius authoredMantas Marcinkevičius authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
MinBucket.md 1.51 KiB
Min Bucket Aggregation
More info about Min bucket aggregation is in the official elasticsearch docs
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
{
"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:
$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();