# Error with a groovy script

**URL:** <https://discuss.elastic.co/t/error-with-a-groovy-script/67274>\
**Category:** Elasticsearch\
**Created:** [November 27, 2016, 4:42pm UTC](https://discuss.elastic.co/t/error-with-a-groovy-script/67274 "2016-11-27T16:42:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amolbpatil](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@amolbpatil](https://discuss.elastic.co/u/amolbpatil)\
**Post date:** [November 27, 2016, 4:42pm UTC](https://discuss.elastic.co/t/error-with-a-groovy-script/67274/1 "2016-11-27T16:42:24Z")

</div>

Hi,  
I'm using ES 2.3.1, and I've written a simple groovy script which merges the documents. Script loads well and runs good at times, but after some time it gives an error: message [java.lang.IllegalArgumentException: failed to execute script]

What could be wrong ? How can I debug more ? Can we catch exceptions in groovy script ? Or log ?

My script is given below:

if (ctx.\_source.'field-1' != null) {  
ctx.\_source.'num\_hits' = ctx.\_source.'field-1'.size() + one  
} else {  
ctx.\_source.'num\_hits' = one  
}  
if (ctx.\_source.'field-1' != null) {  
ctx.\_source.'field-1'.add(param\_1)  
} else {  
ctx.\_source.'field-1' = [param\_1]  
}  
if (ctx.\_source.'field-2' != null) {  
ctx.\_source.'field-2'.add(param\_2)  
} else {  
ctx.\_source.'field-2' = [param\_2]  
}  
if (ctx.\_source.'field-3' != null) {  
ctx.\_source.'field-3'.add(param\_3)  
} else {  
ctx.\_source.'field-3' = [param\_3]  
}  
if (ctx.\_source.'field-4' != null) {  
ctx.\_source.'field-4'.add(param\_4)  
} else {  
ctx.\_source.'field-4' = [param\_4]  
}

field-1, and field-3 are string arrays.  
field-2 and field-4 are long arrays.  
I always pass on at-least 5 params: one, param\_1, param\_2, param\_3, param\_4 (plus there could be more params)  
one is int, param\_1 and param\_3 are strings, param\_2 and param\_4 are longs.

Thanks,  
..... Amol

---

<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:** [December 25, 2016, 4:43pm UTC](https://discuss.elastic.co/t/error-with-a-groovy-script/67274/2 "2016-12-25T16:43:03Z")

</div>

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