I tried writing the trigger condition in same format as suggested but getting error:
My monitor output:
{
"_shards": {
"total": 1,
"failed": 0,
"successful": 1,
"skipped": 0
},
"hits": {
"hits": [],
"total": {
"value": 23,
"relation": "eq"
},
"max_score": null
},
"took": 26,
"timed_out": false,
"aggregations": {
"data_aggs_interval": {
"buckets": [
{
"key_as_string": "2022-11-24T00:00:00.000Z",
"doc_count": 8,
"tag_names": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 2,
"buckets": [
{
"doc_count": 3,
"metrics": {
"value": 3000
},
"key": "I_DRV155_CFB"
},
{
"doc_count": 3,
"metrics": {
"value": 197
},
"key": "M_E2MDD_CFB"
}
]
},
"key": 1669248000000
},
{
"key_as_string": "2022-12-04T00:00:00.000Z",
"doc_count": 15,
"tag_names": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1,
"buckets": [
{
"doc_count": 10,
"metrics": {
"value": 197
},
"key": "M_E2MDD_CFB"
},
{
"doc_count": 4,
"metrics": {
"value": 197
},
"key": "I_RM3201_RTD_08"
}
]
},
"key": 1670112000000
}
]
}
}
}
If I try to access first bucket, the trigger condition is working:
First bucket trigger condition:
return ctx.results[0].aggregations.data_aggs_interval.buckets[0].tag_names.buckets[0].metrics.value == null ? false:
(ctx.results[0].aggregations.data_aggs_interval.buckets[0].tag_names.buckets[0].metrics.value >= 3000 &&
ctx.results[0].aggregations.data_aggs_interval.buckets[0].tag_names.buckets[0].key == "I_DRV155_CFB")
Using loops , it can be achieved as below.
For loop trigger condition:
int score = 0;
for (int i = 0; i < ctx.results[0].aggregations.data_aggs_interval.buckets.size(); i++)
{
if (ctx.results[0].aggregations.data_aggs_interval.buckets[i].tag_names.buckets[i].metrics.value == null ? false:
ctx.results[0].aggregations.data_aggs_interval.buckets[i].tag_names.buckets[i].metrics.value >= 3000 &&
ctx.results[0].aggregations.data_aggs_interval.buckets[i].tag_names.buckets[i].key == "I_DRV155_CFB")
{
score += 10;
}
}
if (score > 0) {
return true;
} else {
return false;
}