Watcher condition script throws an null pointer exception

alerting

#1

I am trying to access the ctx fields in the condition script

"result": {
"execution_time": "2018-11-09T16:42:43.944Z",
"execution_duration": 84,
"input": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 90,
"failed": 0,
"successful": 90,
"skipped": 0
},
"hits": {
"hits": ,
"total": 2968,
"max_score": 0
},
"took": 58,
"timed_out": false,
"aggregations": {
"messages": {
"meta": {},
"buckets": {
"errors": {
"doc_count": 1033,
"host": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"meta": {},
"buckets": [
{
"doc_count": 887,
"time": {
"doc_count": 887,
"meta": {},
"tophit": {
"hits": {
"hits": [
{
"_index": "filebeat-6.4.1-2018.11.08",
"_type": "doc",
"_source": {
"offset": 328587,
"prospector": {
"type": "log"
},
"source": "/var/log/elasticsearch/server1/xxx.log",
"fileset": {
"module": "elasticsearch",
"name": "server"
},
"message": "[2018-11-08T09:03:42,745][DEBUG][o.e.a.a.i.s.TransportIndicesStatsAction] ...",
"type": "beats",
"tags": [
"beats_input_codec_plain_applied"
],
"input": {
"type": "log"
},
"@timestamp": "2018-11-08T15:22:03.172Z",
"service": {
"name": "elasticsearch"
},
"@version": "1",
"beat": {
"hostname": "server1",
"name": "server1",
"version": "6.4.1"
},
"host": {
"name": "server1"
}
},
"_id": "xxx",
"_score": 5.5517254
}
],
"total": 887,
"max_score": 5.5517254
}
}
},
"key": "server1"
},

Condition script:

{
"script": {
"lang": "painless",
"source": "return ctx.payload.aggregations.messages.buckets.errors.host.buckets.stream().anyMatch(b -> b.tophit.hits.total > params.total)",
"params": {"total": 1}
}

But it throws as error as follows

"exception": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"b -> b.tophit.hits.total > params.total)",
" ^---- HERE"
],
"script": "condition",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null,
"stack_trace": "java.lang.NullPointerException\n\tat org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:203)\n\tat org.elasticsearch.painless.PainlessScript$Script.lambda$0(condition:101)\n\tat org.elasticsearch.painless.PainlessScript$Script$$Lambda0.test(Unknown Source)\n\tat java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)\n\tat java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1359)\n\tat java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)\n\tat java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)\n\tat java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)\n\tat java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)\n\tat java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)\n\tat java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)\n\tat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\n\tat java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:449)\n\tat java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)\n\tat org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:212)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute(condition:88)\n\tat org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.doExecute(ScriptCondition.java:73)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.execute(ScriptCondition.java:64)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:443)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:295)\n\tat org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction$1.doRun(TransportExecuteWatchAction.java:154)\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\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"
},

Can anyone help me with the condition script format


#2

This is resolved
Thanks!


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.