Hello,
I want to calculate the ratio of orders/searches per customer number in my erp and send an alert with that info.
So i have created an advance alert with the following code:
{
"trigger": {
"schedule": {
"cron": "0 0/2 * 1/1 * ? *"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"connect-*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"aggs": {
"convratepercustomer_account": {
"terms": {
"field": "customer_nr"
},
"aggs": {
"total_orders": {
"filter": {
"term": {
"order_type": "ORDER"
}
}
}
},
"total_searches": {
"filter": {
"term": {
"must": [
{
"terms": {
"event_type": [
"fulltextsearch",
"fahrzeugsuche",
"teilesuche"
]
}
}
]
}
}
},
"bucket_script": {
"buckets_path": {
"totalorders": "total_orders",
"totalsearches": "total_searches"
},
"script": "params.totalorders / params.totalsearches * 100"
}
}
}
}
}
}
},
"condition": {
"always": {}
},
"actions": {
"send_email": {
"email": {
"profile": "standard",
"to": [
"alexandros.ananikidis@sag-ag.ch"
],
"subject": "{{#ctx.payload.aggregations.convratepercustomer_account}}",
"body": {
"text": "ole"
}
}
}
}
}
but the error response that i get is the following:
{
"_id" : "conversion_report_07c4c121-90c9-45ac-a6ed-d06332252db2-2020-07-15T14:12:01.04247Z",
"watch_record" : {
"watch_id" : "conversion_report",
"node" : "IQhDHLCVRXCAKsejaLyT-w",
"state" : "failed",
"user" : "elastic",
"status" : {
"state" : {
"active" : false,
"timestamp" : "2020-07-15T14:11:56.357Z"
},
"actions" : {
"send_email" : {
"ack" : {
"timestamp" : "2020-07-15T14:11:56.357Z",
"state" : "awaits_successful_execution"
}
}
},
"execution_state" : "failed",
"version" : 20
},
"trigger_event" : {
"type" : "manual",
"triggered_time" : "2020-07-15T14:12:01.042Z",
"manual" : {
"schedule" : {
"scheduled_time" : "2020-07-15T14:12:01.042Z"
}
}
},
"input" : {
"search" : {
"request" : {
"search_type" : "query_then_fetch",
"indices" : [
"connect-*"
],
"rest_total_hits_as_int" : true,
"body" : {
"size" : 0,
"aggs" : {
"convratepercustomer_account" : {
"terms" : {
"field" : "customer_nr"
},
"aggs" : {
"total_orders" : {
"filter" : {
"term" : {
"order_type" : "ORDER"
}
}
}
},
"total_searches" : {
"filter" : {
"term" : {
"must" : [
{
"terms" : {
"event_type" : [
"fulltextsearch",
"fahrzeugsuche",
"teilesuche"
]
}
}
]
}
}
},
"bucket_script" : {
"buckets_path" : {
"totalorders" : "total_orders",
"totalsearches" : "total_searches"
},
"script" : "params.totalorders / params.totalsearches * 100"
}
}
}
}
}
}
},
"condition" : {
"always" : { }
},
"metadata" : {
"xpack" : {
"type" : "json"
}
},
"result" : {
"execution_time" : "2020-07-15T14:12:01.042Z",
"execution_duration" : 0,
"input" : {
"type" : "search",
"status" : "failure",
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "Found two aggregation type definitions in [convratepercustomer_account]: [terms] and [total_searches]",
"line" : 1,
"col" : 166
}
],
"type" : "parsing_exception",
"reason" : "Found two aggregation type definitions in [convratepercustomer_account]: [terms] and [total_searches]",
"line" : 1,
"col" : 166
},
"search" : {
"request" : {
"search_type" : "query_then_fetch",
"indices" : [
"connect-*"
],
"rest_total_hits_as_int" : true,
"body" : {
"size" : 0,
"aggs" : {
"convratepercustomer_account" : {
"terms" : {
"field" : "customer_nr"
},
"aggs" : {
"total_orders" : {
"filter" : {
"term" : {
"order_type" : "ORDER"
}
}
}
},
"total_searches" : {
"filter" : {
"term" : {
"must" : [
{
"terms" : {
"event_type" : [
"fulltextsearch",
"fahrzeugsuche",
"teilesuche"
]
}
}
]
}
}
},
"bucket_script" : {
"buckets_path" : {
"totalorders" : "total_orders",
"totalsearches" : "total_searches"
},
"script" : "params.totalorders / params.totalsearches * 100"
}
}
}
}
}
}
},
"actions" : [ ]
},
"messages" : [
"failed to execute watch input"
]
}
}
What shall i change to make it work?