Watcher Condition "script" : { "script" : ""}}. Not working

Tried using the example mentioned in the documents for scripts inside condition block. It is throwing an error.
Will appreciate any pointers.

"condition" : {
"script" : {
"script" : "return ctx.payload.hits.total > threshold",
"params" : {
"threshold" : 5
}
}
}

Error:

{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "unexpected field [script]"
}
],
"type": "parse_exception",
"reason": "could not parse [script] condition for watch [sample_watcher]. failed to parse script",
"caused_by": {
"type": "parse_exception",
"reason": "unexpected field [script]"
}
},
"status": 400
}

1 Like

try this instead (note s/script/inline)

{
  "condition": {
    "script": {
      "inline": "return ctx.payload.hits.total > threshold",
      "params": {
        "threshold": 5
      }
    }
  }
}

https://www.elastic.co/guide/en/watcher/current/condition.html#_using_a_script_condition

Yes, the inline worked. So s/script/script is not a valid command.

I tried your example and I got this error:
{ "error": { "root_cause": [ { "type": "script_exception", "reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits.total > threshold] of type [groovy]" } ], "type": "script_exception", "reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [return ctx.payload.hits.total > threshold] of type [groovy]" }, "status": 500 }

What can I do to solve this problem ?

Im also receiving the same error when attempting to setup a new watch.
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.memory && node.memory.value >= 75;] of type [groovy]"
}
],
"type": "script_exception",
"reason": "failed to compile script [ScriptException[scripts of type [inline], operation [elasticsearch-watcher_watch] and lang [groovy] are disabled]] with lang [if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.memory && node.memory.value >= 75;] of type [groovy]"
},
"status": 500
}

Reference: https://www.elastic.co/guide/en/watcher/current/watching-marvel-data.html#watching-memory-usage

Any help would be grateful.

I Fixed my error:
the problem was on my elasticsearch.yml

I added this :

script.inline: on
script.indexed: on

and now it is working

1 Like

Thanks @carmelom. I added those two lines throughout my nodes and master and it has accepted the script.

oh !thank you, my friend . my es script is working now!