# Watcher condition script throws an null pointer exception

**URL:** https://discuss.elastic.co/t/watcher-condition-script-throws-an-null-pointer-exception/156092
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [November 9, 2018, 5:37pm UTC](https://discuss.elastic.co/t/watcher-condition-script-throws-an-null-pointer-exception/156092 "2018-11-09T17:37:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shiv94](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@shiv94](https://discuss.elastic.co/u/shiv94)
#### Post date: [November 9, 2018, 5:37pm UTC](https://discuss.elastic.co/t/watcher-condition-script-throws-an-null-pointer-exception/156092/1 "2018-11-09T17:37:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![shiv94](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@shiv94](https://discuss.elastic.co/u/shiv94)
#### Post date: [November 9, 2018, 6:35pm UTC](https://discuss.elastic.co/t/watcher-condition-script-throws-an-null-pointer-exception/156092/2 "2018-11-09T18:35:05Z")

</div>

This is resolved  
Thanks!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 7, 2018, 6:49pm UTC](https://discuss.elastic.co/t/watcher-condition-script-throws-an-null-pointer-exception/156092/3 "2018-12-07T18:49:14Z")

</div>

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