-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
:Analytics/AggregationsAggregationsAggregations
Description
I get result by using bucket script aggregation, but I can't sort by this aggregation value. For explame,
{
"from": 0,
"size": 0,
"sort": [],
"aggs": {
"api_terms": {
"terms": {
"field": "name",
"order": {
"avg_time": "desc"
}
},
"aggs": {
"sum_duration": {
"sum": {
"field": "duration"
}
},
"sum_count": {
"sum": {
"field": "count"
}
},
"avg_time": {
"bucket_script": {
"buckets_path": {
"duration": "sum_duration",
"count": "sum_count"
},
"script": "params.duration / params.count"
}
}
}
}
}
}
I hope sort by "avg_time" that is calculated by bucket_script, so I add order in term aggregation ( "order": {"avg_time": "desc"}). But it cause error. This reason of error is “Invalid aggregator order path [avg_time]. Unknown aggregation [avg_time]".
Even more puzzling is I use add order by sum_count instead of avg_time, i can get correct value.
rahulsinghaijzzfs
Metadata
Metadata
Assignees
Labels
:Analytics/AggregationsAggregationsAggregations