Elastic search watcher : Unable to fix this error

 "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,

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

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.

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"
}
}

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