Hi,
I am new to Opensearch Alerts and I am trying to do an alert based on percentage values of doc from one method over the total methods triggered in a specific timeframe. I bulit the following query:
GET methods/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"timestamp": {
"from": "now-1h",
"to": "now",
"include_lower": true,
"include_upper": true,
"format": "epoch_millis",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggs": {
"filters_agg": {
"filters": {
"filters": {
"sourceCount": {
"match_all": {}
}
}
},
"aggs": {
"total_method_count": {
"value_count": {
"field": "id"
}
},
"method_one": {
"filter": {
"term": {
"method.keyword": "one"
}
},
"aggs": {
"total_count": {
"value_count": {
"field": "id"
}
}
}
},
"method_one_percentage":
{
"bucket_script": {
"buckets_path": {
"methodOneCount": "method_one>total_count",
"totalMethodCount": "total_method_count"
},
"script": "params.methodOneCount / params.totalMethodCount * 100"
}
}
}
}
}
}
which gives the following output
{
"took": 37,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 4,
"skipped": 3,
"failed": 0
},
"hits": {
"total": {
"value": 331,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"filters_agg": {
"buckets": {
"sourceCount": {
"doc_count": 331,
"method_one": {
"doc_count": 228,
"total_count": {
"value": 228
}
},
"total_method_count": {
"value": 331
},
"method_one_percentage": {
"value": 68.8821752265861
}
}
}
}
}
}
How can I use the above in the bucket triggers to trigger an alert when method_one_percentage
is below 50 ?
Thanks