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

**URL:** https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [January 20, 2016, 10:36pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710 "2016-01-20T22:36:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rohitgup14](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rohitgup14](https://discuss.elastic.co/u/rohitgup14)
#### Post date: [January 20, 2016, 10:36pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/1 "2016-01-20T22:36:40Z")

</div>

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  
}

---

<div class="post-metadata">

### Author: ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)
#### Post date: [January 20, 2016, 11:23pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/2 "2016-01-20T23:23:20Z")

</div>

try this instead (note s/script/inline)

```auto
{
  "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](https://www.elastic.co/guide/en/watcher/current/condition.html#_using_a_script_condition)

---

<div class="post-metadata">

### Author: ![rohitgup14](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@rohitgup14](https://discuss.elastic.co/u/rohitgup14)
#### Post date: [January 21, 2016, 7:05pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/3 "2016-01-21T19:05:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![carmelom](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@carmelom](https://discuss.elastic.co/u/carmelom)
#### Post date: [February 1, 2016, 2:09pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/4 "2016-02-01T14:09:18Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![pgcr](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pgcr](https://discuss.elastic.co/u/pgcr)
#### Post date: [February 2, 2016, 7:44pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/5 "2016-02-02T19:44:56Z")

</div>

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](https://www.elastic.co/guide/en/watcher/current/watching-marvel-data.html#watching-memory-usage)

Any help would be grateful.

---

<div class="post-metadata">

### Author: ![carmelom](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@carmelom](https://discuss.elastic.co/u/carmelom)
#### Post date: [February 3, 2016, 8:44am UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/6 "2016-02-03T08:44:55Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pgcr](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pgcr](https://discuss.elastic.co/u/pgcr)
#### Post date: [February 3, 2016, 2:54pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/7 "2016-02-03T14:54:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Lu1Lu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lu1lu/32/8024_2.png) [@Lu1Lu](https://discuss.elastic.co/u/Lu1Lu)
#### Post date: [February 23, 2016, 7:52am UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/8 "2016-02-23T07:52:26Z")

</div>

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

---

<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: [July 6, 2017, 1:46pm UTC](https://discuss.elastic.co/t/watcher-condition-script-script-not-working/39710/9 "2017-07-06T13:46:54Z")

</div>


