# Watcher script error

**URL:** <https://discuss.elastic.co/t/watcher-script-error/93956>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [July 20, 2017, 1:56pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956 "2017-07-20T13:56:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmbtenorio](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@mmbtenorio](https://discuss.elastic.co/u/mmbtenorio)\
**Post date:** [July 20, 2017, 1:56pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/1 "2017-07-20T13:56:57Z")

</div>

I'm migrating a watch created in ES 2.3 into ES 5.5, it works in ES 2.3, however there's a script error when I tried to run it in ES 5.5

This is the watch:

```
PUT _xpack/watcher/watch/Duplicate_Cost_Invoice_Watch
{
  "trigger": {
    "schedule": {
      "interval": "7300d"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "costing_requests"
        ],
        "types": [],
        "body": {
          "size": 0,
          "aggs": {
            "duplicateCount": {
              "terms": {
                "field": "costInvoiceNumber",
                "min_doc_count": 2,
                "size": 1000
              },
              "aggs": {
                "duplicateDocuments": {
                  "top_hits": {}
                }
              }
            }
          },
          "query": {
            "range": {
              "@timestamp": {
                "gte": "2017-03-01",
                "lte": "2017-03-20"
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "inline": "return ctx.payload.aggregations.duplicateCount.buckets.size() > 0;"
    }
  },
  "transform": {
    "script": {
      "inline": "def total=0; ctx.payload.aggregations.duplicateCount.buckets.each { total += it.doc_count }; return total;"
    }
  },
  "throttle_period": "7300d",
  "actions": {
    "log": {
      "logging": {
        "level": "info",
        "text": "Total: {{ctx.payload._value}}"
      }
    },
    "notify-slack": {
      "throttle_period": "7300d",
      "slack": {
        "account": "monitoring",
        "message": {
          "from": "Duplicate Cost Invoice Watch PROD",
          "to": [
            "#watchertest"
          ],
          "text": "Duplicate Watch found duplicate cost invoices",
          "icon": ":eyes:",
          "attachments": [
            {
              "color": "danger",
              "title": "Duplicate Cost Invoices found in the costing_requests ELK index",
              "text": "There are a total of {{ctx.payload._value}} record/s from March 1 - 20, 2017 that need to be checked for duplicates"
            }
          ]
        }
      }
    }
  }
}

```

This is the error I'm getting:

```
{
  "error": {
    "root_cause": [
      {
        "type": "general_script_exception",
        "reason": "failed to compile script [ScriptException[compile error]; nested: IllegalArgumentException[unexpected token ['{'] was expecting one of [{<EOF>, ';'}].];]"
      }
    ],
    "type": "general_script_exception",
    "reason": "failed to compile script [ScriptException[compile error]; nested: IllegalArgumentException[unexpected token ['{'] was expecting one of [{<EOF>, ';'}].];]"
  },
  "status": 500
}

```

Any suggestions or help is appreciated.  
Thank you.

---

<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:** [July 20, 2017, 2:22pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/2 "2017-07-20T14:22:39Z")

</div>

Hey,

the default scripting language in Elasticsearch 5.0 and above is painless, which has a different syntax than groovy, which is the default in Elasticsearch 2.3. Either you convert your script to painless or you use the groovy plugin.

FYI: We changed the default scripting language, because we wanted a secure fast scripting language and thus we wrote our own. You can read more about it at  
[https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless.html)

--Alex

---

<div class="post-metadata">

**Author:** ![mmbtenorio](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@mmbtenorio](https://discuss.elastic.co/u/mmbtenorio)\
**Post date:** [July 20, 2017, 2:38pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/3 "2017-07-20T14:38:18Z")

</div>

Thanks for the link and the information. I'll try this and get back to you.

Cheers!

- Marge

---

<div class="post-metadata">

**Author:** ![mmbtenorio](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@mmbtenorio](https://discuss.elastic.co/u/mmbtenorio)\
**Post date:** [July 20, 2017, 7:57pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/4 "2017-07-20T19:57:35Z")

</div>

Did this on my elasticsearch.yml file. Did I put the correct syntax? Because I'm still getting the same error 😕

```
script.engine.groovy.inline.xpack_watch: true
script.engine.groovy.inline.search: true
```

---

<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:** [July 28, 2017, 7:19am UTC](https://discuss.elastic.co/t/watcher-script-error/93956/5 "2017-07-28T07:19:47Z")

</div>

You have to specify the scripting language you want to use as part of your watch, inside of the `script` block. Use `"lang": "groovy"`

--Alex

---

<div class="post-metadata">

**Author:** ![mmbtenorio](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@mmbtenorio](https://discuss.elastic.co/u/mmbtenorio)\
**Post date:** [August 2, 2017, 3:45pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/6 "2017-08-02T15:45:37Z")

</div>

Thanks. It worked! 😁

---

<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:** [August 30, 2017, 3:45pm UTC](https://discuss.elastic.co/t/watcher-script-error/93956/7 "2017-08-30T15:45:55Z")

</div>

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