Hi all and sorry for my poor english
I need to calculate percentage of usageTime per services in a json like that
{
"myID": "-1819947444",
"accountUuid": "account-1",
"serviceName": "Dazn299",
"usageTime": 5
}
I try with this , with no result
{
"aggs": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term":{
"accountUuid": "account-1"
}
}
]
}
},
"aggs": {
"usage_time_bucket": {
"terms": {
"field": "usageTime"
},
"aggs": {
"usage_time_histogram" : {
"date_histogram" : {
"field" : "currentDate",
"interval" : "day"
},
"aggs": {
"category": {
"terms": {
"field": "myCategory"
} ,
"aggs": {
"services": {
"terms": {
"field": "serviceName"
} ,
"aggs":{
"usageTimePerService": {
"sum": {
"field": "usageTime"
}
}
}
},
"totalUsageTime": {
"sum": {
"field": "usageTime"
}
} ,
"script_to_get_ratio": {
"bucket_script": {
"buckets_path": {
"numerator": "services['usageTimePerService']",
"denominator": "totalUsageTime"
},
"script": "params.numerator / params.denominator"
}
}
}
}
}
}
}
}
}
}
},
"size": 0
}
But I cannot reach my purpose