I know this query works. However it does not work when the value of either "failed" or "declined" is not present.
GET /metrics-*/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"terms": {
"transaction_lifecycle_event": [
"AUTHORIZATION_DECLINED",
"AUTHORIZATION_FAILED",
"AUTHORIZATION_SUBMITTED"
]
}
}
]
}
},
"aggs": {
"payment_methods": {
"terms": {
"field": "type"
},
"aggs": {
"auths": {
"terms": {
"field": "lifecycle_event"
}
},
"auth_rate": {
"bucket_script": {
"gap_policy": "insert_zeros",
"buckets_path": {
"declined": "auths['AUTHORIZATION_DECLINED']>_count",
"failed": "auths['AUTHORIZATION_FAILED']>_count",
"denominator": "auths['AUTHORIZATION_SUBMITTED']>_count"
},
"script": "((params.denominator - params.declined + params.failed) / params.denominator) * 100"
}
}
}
}
}
}
Is there a way to have a default value of 0 for failed/declined in the bucket?
I tried "gap_policy": "insert_zeros",
but got
"caused_by" : {
"type" : "null_pointer_exception",
"reason" : "Cannot invoke \"Object.getClass()\" because \"right\" is null"
}
Without the gap policy, there is no "auth_rate" value in the result