I would like to have a watch with script condition which returns true based on condition in my inner most for loop.
I have logic created with labeled for loop, as it is part of the Java control flow mentioned in doc here
def status = false;
top_loop:for (item_a in ctx.payload.aggregations.by_A.buckets) {
def a = item_a.key;
for (item_b in item_a.by_B.buckets) {
def b = item_b.key;
for (item_c in item_b.by_C.buckets) {
def c = item_c.key;
def alert_count = item_c.D.value;
if (alert_count > 1) {
status = true;
break top_loop;
}
}
}
}
return status;
This script is returning compilation errors:
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"...\ntop_loop:for (item_a in ctx. ...",
" ^---- HERE"
],
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "unexpected token [':'] was expecting one of [{<EOF>, ';'}]."
}
Need suggestion to resolve this.
Thanks
Update: Using ES, x-pack 5.4