Hi All,
I have configured a watcher and added the following condition:
"condition": {
"script": {
"source": "boolean trigger=false;ArrayList offenders = new ArrayList();if (ctx.payload.aggregations.login.buckets.size() > 0) { for (int i=0;i<ctx.payload.aggregations.login.buckets.size();i++) { if (ctx.payload.aggregations.login.buckets[i].source_countries.buckets.size() >= 3) { offenders.add(ctx.payload.aggregations.login.buckets[i]); trigger=true; } }}ctx.vars.offenders=offenders;trigger=true;return trigger;",
"lang": "painless"
}
}
Running the watcher produces the below error and I fail to see why..
"exception": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if (ctx.payload.aggregations.login.buckets.size() > 0) { ",
" ^---- HERE"
],
"script": "boolean trigger=false;ArrayList offenders = new ArrayList();if (ctx.payload.aggregations.login.buckets.size() > 0) { for (int i=0;i<ctx.payload.aggregations.login.buckets.size();i++) { if (ctx.payload.aggregations.login.buckets[i].source_countries.buckets.size() >= 3) { offenders.add(ctx.payload.aggregations.login.buckets[i]); trigger=true; } }}ctx.vars.offenders=offenders;trigger=true;return trigger;",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null,
"stack_trace": "java.lang.NullPointerException\n\tat org.elasticsearch.painless.DefBootstrap$PIC.checkClass(DefBootstrap.java:143)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute(boolean trigger=false;ArrayList offenders = new ArrayList();if (ctx.payload.aggregations.login.buckets.size() > 0) { for (int i=0;i<ctx.payload.aggregations.login.buckets.size();i++) { if (ctx.payload.aggregations.login.buckets[i].source_countries.buckets ...:89)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.doExecute(ScriptCondition.java:66)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.execute(ScriptCondition.java:57)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:434)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:295)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.lambda$executeAsync$5(ExecutionService.java:395)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:544)\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:624)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat java.lang.Thread.run(Thread.java:748)\n"
}
The data I get from my query / aggregation looks like this.
{
"took" : 620,
"timed_out" : false,
"_shards" : {
"total" : 20,
"successful" : 20,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2079,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"logins" : {
"doc_count_error_upper_bound" : 20,
"sum_other_doc_count" : 1005,
"buckets" : [
{
"key" : "foo1@bar.nl",
"doc_count" : 307,
"source_countries" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 68,
"buckets" : [
{
"key" : "Brazil",
"doc_count" : 75
},
{
"key" : "United States",
"doc_count" : 43
},
{
"key" : "Russia",
"doc_count" : 31
},
{
"key" : "Indonesia",
"doc_count" : 21
},
{
"key" : "India",
"doc_count" : 20
},
{
"key" : "Bangladesh",
"doc_count" : 12
},
{
"key" : "Thailand",
"doc_count" : 10
},
{
"key" : "China",
"doc_count" : 9
},
{
"key" : "Iraq",
"doc_count" : 9
},
{
"key" : "South Africa",
"doc_count" : 9
}
]
}
},
{
"key" : "foo@bar.nl",
"doc_count" : 122,
"source_countries" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Ireland",
"doc_count" : 122
}
]
}
}
]
}
}
}
Could someone please help?
Thanks..