# Issue migrating watchers to latest

**URL:** <https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 13, 2017, 9:43am UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866 "2017-10-13T09:43:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun\_kumar2](https://avatars.discourse-cdn.com/v4/letter/v/97f17d/32.png) [@varun\_kumar2](https://discuss.elastic.co/u/varun_kumar2)\
**Post date:** [October 13, 2017, 9:43am UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866/1 "2017-10-13T09:43:46Z")

</div>

I am trying to migrate my watcher to the latest elastic search Xpack

Here is my condition script

"condition": {  
"script": {  
"inline": "def sf = new SimpleDateFormat('yyyy-MM-dd');ctx.vars.from = sf.parse(new Date());if (ctx.payload.aggregations.minutes20.buckets.size() == 0) return false;def latest = ctx.payload.aggregations.minutes20.buckets[-1]; return latest.occurences.buckets.any{it.doc\_count \> 0};",  
"lang": "painless"  
}

```
},

```

i am having issues compiling the watcher. below are the error details

{  
"error": {  
"root\_cause": [  
{  
"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"... st.occurences.buckets.Any{it.doc\_count \> 0};",  
" ^---- HERE"  
],  
"script": "def sf = new SimpleDateFormat('yyyy-MM-dd');ctx.vars.from = sf.parse(new Date());if (ctx.payload.aggregations.minutes20.buckets.size() == 0) return false;def latest = ctx.payload.aggregations.minutes20.buckets[-1]; return latest.occurences.buckets.Any{it.doc\_count \> 0};",  
"lang": "painless"  
}  
],  
"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"... st.occurences.buckets.Any{it.doc\_count \> 0};",  
" ^---- HERE"  
],  
"script": "def sf = new SimpleDateFormat('yyyy-MM-dd');ctx.vars.from = sf.parse(new Date());if (ctx.payload.aggregations.minutes20.buckets.size() == 0) return false;def latest = ctx.payload.aggregations.minutes20.buckets[-1]; return latest.occurences.buckets.Any{it.doc\_count \> 0};",  
"lang": "painless",  
"caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "unexpected token ['{'] was expecting one of [{, ';'}]."  
}  
},  
"status": 500  
}

---

<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:** [October 13, 2017, 10:04am UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866/2 "2017-10-13T10:04:10Z")

</div>

you need to either install the old groovy plugin or convert your scripts to the new painless language. If you need to access the time the watch was running, you should check out `ctx.trigger.triggered_time` - as you cannot instantiate a new date object anymore.

you also need to replace groovy closures with java lambdas,

i.e.

```auto
ctx.payload.foo.bar.buckets.stream().anyMatch(item -> item.whateverfield > 6)

```

hope htis helps to get started. There is also the painless documentation [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-painless.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-painless.html)

---

<div class="post-metadata">

**Author:** ![varun\_kumar2](https://avatars.discourse-cdn.com/v4/letter/v/97f17d/32.png) [@varun\_kumar2](https://discuss.elastic.co/u/varun_kumar2)\
**Post date:** [October 13, 2017, 11:00am UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866/3 "2017-10-13T11:00:34Z")

</div>

> [@spinscale](#):
>
> install the old groovy plugin

How can i install the old groovy plugin int he new env?

---

<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:** [October 13, 2017, 12:57pm UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866/4 "2017-10-13T12:57:12Z")

</div>

Sorry, my bad... groovy is still part of Elasticsearch 5.x, no need to install anything. You need to specify `lang: groovy` in your script part though.

Word of warning; Groovy as scripting language will be removed in Elasticsearch 6.0

---

<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:** [November 10, 2017, 12:57pm UTC](https://discuss.elastic.co/t/issue-migrating-watchers-to-latest/103866/5 "2017-11-10T12:57:50Z")

</div>

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