# Elastic search watcher : Unable to fix this error

**URL:** <https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [August 23, 2018, 8:52am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683 "2018-08-23T08:52:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeruvavasavi](https://avatars.discourse-cdn.com/v4/letter/y/258eb7/32.png) [@yeruvavasavi](https://discuss.elastic.co/u/yeruvavasavi)\
**Post date:** [August 23, 2018, 8:52am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683/1 "2018-08-23T08:52:14Z")

</div>

```
 "total": 41,
      "failed": 0,
      "successful": 41,
      "skipped": 0
    },
    "hits": {
      "hits": [],
      "total": 411225,
      "max_score": 0
    },
    "took": 18,
    "timed_out": false
  },
  "search": {
    "request": {
      "search_type": "query_then_fetch",
      "indices": [
        "metric*"
      ],
      "types": [],
      "body": {
        "size": 0,
        "query": {
          "match_phrase": {
            "system.process.state": "sleeping"
          }
        }
      }
    }
  }
},
"actions": []

```

},  
"exception": {  
"type": "script\_exception",  
"reason": "runtime error",  
"script\_stack": [  
"ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last ",  
" ^---- HERE"  
],  
"script": " ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last ",  
"lang": "painless",  
"caused\_by": {  
"type": "null\_pointer\_exception",  
"reason": null,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 23, 2018, 9:07am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683/2 "2018-08-23T09:07:32Z")

</div>

please provide the **full output** of the execute watch API instead of just snippets. Also, please properly format that output like you did with the first snippet. This just makes it endlessly more readable!

Thanks a lot!

--Alex

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 23, 2018, 9:08am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683/3 "2018-08-23T09:08:59Z")

</div>

My quick assumption here is, that you specified `size: 0` in your search, and this no hits are being returned. In addition you are using `ctx.payload.hits` to access the hits array, but this is not where it is. Lastly, you are trying to access the `_source`, but again this is inside of the hits array, so you have to specify which element you want to access.

---

<div class="post-metadata">

**Author:** ![yeruvavasavi](https://avatars.discourse-cdn.com/v4/letter/y/258eb7/32.png) [@yeruvavasavi](https://discuss.elastic.co/u/yeruvavasavi)\
**Post date:** [August 23, 2018, 9:17am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683/4 "2018-08-23T09:17:07Z")

</div>

I am new to elastic. Here i want to check a condition using match query and if that is met i want to update that field with another value. Following is my code.

{  
"watch\_id": "_inlined_",  
"node": "vZk889z2RhOLAoR7Wtf1Dg",  
"state": "failed",  
"status": {  
"state": {  
"active": true,  
"timestamp": "2018-08-23T08:37:31.628Z"  
},  
"actions": {  
"send\_email": {  
"ack": {  
"timestamp": "2018-08-23T08:37:31.628Z",  
"state": "awaits\_successful\_execution"  
}  
}  
},  
"execution\_state": "failed",  
"version": -1  
},  
"trigger\_event": {  
"type": "manual",  
"triggered\_time": "2018-08-23T08:37:31.635Z",  
"manual": {  
"schedule": {  
"scheduled\_time": "2018-08-23T08:37:31.635Z"  
}  
}  
},  
"input": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"metric\*"  
],  
"types": [],  
"body": {  
"size": 0,  
"query": {  
"match\_phrase": {  
"system.process.state": "sleeping"  
}  
}  
}  
}  
}  
},  
"condition": {  
"script": {  
"source": " ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last ",  
"lang": "painless",  
"params": {  
"last": "Attached"  
}  
}  
},  
"metadata": {  
"xpack": {  
"type": "json"  
}  
},  
"result": {  
"execution\_time": "2018-08-23T08:37:31.635Z",  
"execution\_duration": 19,  
"input": {  
"type": "search",  
"status": "success",  
"payload": {  
"\_shards": {  
"total": 41,  
"failed": 0,  
"successful": 41,  
"skipped": 0  
},  
"hits": {  
"hits": [],  
"total": 411225,  
"max\_score": 0  
},  
"took": 18,  
"timed\_out": false  
},  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"metric\*"  
],  
"types": [],  
"body": {  
"size": 0,  
"query": {  
"match\_phrase": {  
"system.process.state": "sleeping"  
}  
}  
}  
}  
}  
},  
"actions": []  
},  
"exception": {  
"type": "script\_exception",  
"reason": "runtime error",  
"script\_stack": [  
"ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last ",  
" ^---- HERE"  
],  
"script": " ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last ",  
"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:202)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute( ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last :26)\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:454)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:305)\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:626)\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"  
},  
"stack\_trace": "ScriptException[runtime error]; nested: NullPointerException;\n\tat org.elasticsearch.painless.PainlessScript.convertToScriptException(PainlessScript.java:94)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute( ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last :41)\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:454)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:305)\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:626)\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)\nCaused by: java.lang.NullPointerException\n\tat org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:202)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute( ctx.payload.hits.\_source.system.process.state = ctx.payload.hits.\_source.system.process.state + params.last :26)\n\t... 13 more\n"  
}  
}

---

<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:** [September 20, 2018, 9:26am UTC](https://discuss.elastic.co/t/elastic-search-watcher-unable-to-fix-this-error/145683/5 "2018-09-20T09:26:26Z")

</div>

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