I have a query that returns docs aggregated by day, then by an internal metric call LocalRetryCount. I'd like the results to include with the LocalRetryCount buckets what percentage that bucket is of the overall. I found some examples that use a a bucket_script to produce the percentage value, but no results are returned.
My query
{
"size":0,
"query":{
"bool":{
"must":[
{
"range":{
"Timestamp":{
"from":"now-1d",
"to":"now"
}
}
},
{
"query_string":{
"query":"LoggingProcess.ModuleId: 4",
"analyze_wildcard":true
}
}
]
}
},
"aggs":{
"service_calls_per_day":{
"date_histogram":{
"field":"Timestamp",
"interval":"day"
},
"aggs":{
"total_retry_count":{
"value_count":{
"field":"Metrics.Longs.LocalRetryCount"
}
},
"local_retry_count":{
"terms":{
"field":"Metrics.Longs.LocalRetryCount"
}
},
"percentage_script":{
"bucket_script":{
"buckets_path":{
"total_count":"total_retry_count.value",
"retry_count":"local_retry_count.doc_count"
},
"script":"100 * params.total_count / params.retry_count"
}
}
}
}
}
}
The current results
{
"took": 460,
"timed_out": false,
"_shards": {
"total": 42,
"successful": 42,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5934883,
"max_score": 0,
"hits":
},
"aggregations": {
"service_calls_per_day": {
"buckets": [
{
"key_as_string": "2019-01-17T00:00:00.000Z",
"key": 1547683200000,
"doc_count": 2411223,
"total_retry_count": {
"value": 1441179
},
"local_retry_count": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 0,
"doc_count": 1439567
},
{
"key": 1,
"doc_count": 1610
},
{
"key": 2,
"doc_count": 2
}
]
}
},
{
"key_as_string": "2019-01-18T00:00:00.000Z",
"key": 1547769600000,
"doc_count": 3523660,
"total_retry_count": {
"value": 2235449
},
"local_retry_count": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 0,
"doc_count": 2229797
},
{
"key": 1,
"doc_count": 4506
},
{
"key": 2,
"doc_count": 573
},
{
"key": 3,
"doc_count": 367
},
{
"key": 4,
"doc_count": 170
},
{
"key": 5,
"doc_count": 36
}
]
}
}
]
}
}
}
What I'd like is for the local_retry_count buckets to contain the percentage value, but I'm not getting any results from the percentage_script aggregation. Any help is appreciated.