Hi
I'm working to get some KPI on my index where I load the company sales and I would like to calculate the following
Avg Ticket = Total Sales / # Tickets
I'm using the following payload:
{
"size": 0,
"aggs": {
"tot_amount_euro": {
"sum": {
"field": "amt_euro"
}
},
"count_ticket": {
"cardinality": {
"field": "ticket_code.keyword"
}
}
}
}
and I'm getting the values to calculate the the KPI, but I would like to have the value directly from ES and then I'm trying to use the scripting bucket:
{
"size": 0,
"aggs": {
"tot_amount_euro": {
"sum": {
"field": "amt_euro"
}
},
"count_ticket": {
"cardinality": {
"field": "ticket_code.keyword"
},
"avg_ticket": {
"bucket_script": {
"buckets_path": {
"tSales": "tot_amtount_euro",
"tQty": "count_ticket"
},
"script": "params.tSales / params.tQty"
}
}
}
}
}
but I got this error:
"Found two aggregation type definitions in [count_ticket]: [cardinality] and [avg_ticket]"
Any suggestion ?
Thanks