# Duplicate function MVEL script

**URL:** <https://discuss.elastic.co/t/duplicate-function-mvel-script/19497>\
**Category:** Elasticsearch\
**Created:** [August 27, 2014, 2:50pm UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497 "2014-08-27T14:50:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kd1](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kd1](https://discuss.elastic.co/u/kd1)\
**Post date:** [August 27, 2014, 2:50pm UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497/1 "2014-08-27T14:50:11Z")

</div>

Hello

We are executing some concurrent updates on the same document using an MVEL  
script together with some parameters.  
The MVEL script contains some functions such as "addRelations" etc but  
there is no sign of duplicate functions.

ES throws the following error:

[John Kafka][inet[/10.12.1.219:9300]][update]]; nested:  
ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
_CompileException_[[Error: _duplicate function: addRelations_]  
[Near : {... def addRelations(relationNode, ....}]  
^  
[Line: 1, Column: 1]

ES Version 1.3.2

If the updates are executed sequentially there is no error/problem with the  
MVEL script.

Any idea's?

Best Regards,  
Kristof

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [August 27, 2014, 2:55pm UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497/2 "2014-08-27T14:55:57Z")

</div>

I'd port to groovy and try again. MVEL is on its way out and has some  
stability issues anyway. Like, I really think it has some problems  
compiling multiple MVEL scripts concurrently.

Nik

On Wed, Aug 27, 2014 at 10:50 AM, [kd@stylelabs.com](mailto:kd@stylelabs.com) wrote:

> Hello
> 
> We are executing some concurrent updates on the same document using an  
> MVEL script together with some parameters.  
> The MVEL script contains some functions such as "addRelations" etc but  
> there is no sign of duplicate functions.
> 
> ES throws the following error:
> 
> [John Kafka][inet[/10.12.1.219:9300]][update]]; nested:  
> ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
> _CompileException_[[Error: _duplicate function: addRelations_]  
> [Near : {... def addRelations(relationNode, ....}]  
> ^  
> [Line: 1, Column: 1]
> 
> ES Version 1.3.2
> 
> If the updates are executed sequentially there is no error/problem with  
> the MVEL script.
> 
> Any idea's?
> 
> Best Regards,  
> Kristof
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9ec7938a-434d-4610-9a53-5652765b4994%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd1DQqvr8wePzAfTxTvxrk7TnGLi9VBx\_4at3D%3DVHW\_noQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd1DQqvr8wePzAfTxTvxrk7TnGLi9VBx_4at3D%3DVHW_noQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alex\_S\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_s_v/32/1317_2.png) [@Alex\_S\_V](https://discuss.elastic.co/u/Alex_S_V)\
**Post date:** [August 28, 2014, 9:01am UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497/3 "2014-08-28T09:01:02Z")

</div>

The problem with MVEL that you can't redefine defined function in a script  
instance. Script class instantiates once the query starts, and then it's  
executing it again and again. MVEL is bad for complex scripting.  
Yes, you could use groovy,and should 🙂

I found a good way to use it with the next code:

_import_ groovy.lang.Script  
_class_ MyScript _extends_ Script {  
_def_ run() {  
// your code is here, also binded variables should be available here  
}  
}

So how it works:

1. Groovy compiles this script and put to class cache.
2. One each query MyScript instance is created (on per node)
3. On each document run() method is executed (It should provide different  
return values for filter script, score script, sort script, script fields)

Alex

On Wednesday, August 27, 2014 5:50:11 PM UTC+3, [k...@stylelabs.com](mailto:k...@stylelabs.com) wrote:

> Hello
> 
> We are executing some concurrent updates on the same document using an  
> MVEL script together with some parameters.  
> The MVEL script contains some functions such as "addRelations" etc but  
> there is no sign of duplicate functions.
> 
> ES throws the following error:
> 
> [John Kafka][inet[/10.12.1.219:9300]][update]]; nested:  
> ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
> _CompileException_[[Error: _duplicate function: addRelations_]  
> [Near : {... def addRelations(relationNode, ....}]  
> ^  
> [Line: 1, Column: 1]
> 
> ES Version 1.3.2
> 
> If the updates are executed sequentially there is no error/problem with  
> the MVEL script.
> 
> Any idea's?
> 
> Best Regards,  
> Kristof

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e549c53b-90ae-41ca-b106-5c6e812417f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e549c53b-90ae-41ca-b106-5c6e812417f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kd1](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kd1](https://discuss.elastic.co/u/kd1)\
**Post date:** [August 28, 2014, 9:04am UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497/4 "2014-08-28T09:04:11Z")

</div>

Ok thanks for the info, we ported the mvel script to groovy and the  
concurrent operations seem to succeed now 🙂

On Wednesday, August 27, 2014 4:50:11 PM UTC+2, [k...@stylelabs.com](mailto:k...@stylelabs.com) wrote:

> Hello
> 
> We are executing some concurrent updates on the same document using an  
> MVEL script together with some parameters.  
> The MVEL script contains some functions such as "addRelations" etc but  
> there is no sign of duplicate functions.
> 
> ES throws the following error:
> 
> [John Kafka][inet[/10.12.1.219:9300]][update]]; nested:  
> ElasticsearchIllegalArgumentException[failed to execute script]; nested:  
> _CompileException_[[Error: _duplicate function: addRelations_]  
> [Near : {... def addRelations(relationNode, ....}]  
> ^  
> [Line: 1, Column: 1]
> 
> ES Version 1.3.2
> 
> If the updates are executed sequentially there is no error/problem with  
> the MVEL script.
> 
> Any idea's?
> 
> Best Regards,  
> Kristof

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/27310183-8041-445c-b922-1bf80df3474c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/27310183-8041-445c-b922-1bf80df3474c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:05am UTC](https://discuss.elastic.co/t/duplicate-function-mvel-script/19497/5 "2017-07-06T01:05:49Z")

</div>


