# Update api with stored scripts

**URL:** <https://discuss.elastic.co/t/update-api-with-stored-scripts/8236>\
**Category:** Elasticsearch\
**Created:** [June 27, 2012, 5:13am UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236 "2012-06-27T05:13:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 27, 2012, 5:13am UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/1 "2012-06-27T05:13:35Z")

</div>

Hi list. Is it possible to update docs with stored mvel script? I'm getting  
exception

{  
"error" : "ElasticSearchIllegalArgumentException[failed to execute  
script]; nested: PropertyAccessException[[Error: unresolvable property or  
identifier: updatedoc]\n[Near : {... updatedoc ....}]\n  
^\n[Line: 1, Column: 1]]; ",  
"status" : 400  
}

Update request looks like

curl -XPOST '[http://localhost:9200/test/docs/1/\_update?pretty=true](http://localhost:9200/test/docs/1/_update?pretty=true)' -d '{  
"script": "updatedoc",  
"lang": "mvel",  
"params": {  
...  
}

And my updatedoc.js is under elasticsearch/config/scripts/ directory.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 27, 2012, 3:20pm UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/2 "2012-06-27T15:20:58Z")

</div>

Yes, you can, though setting the lang is not relevant when using scripts  
that are registered on the node level, the language is detected based on  
the extension of the file, in which case its javascript cause you call it  
update.js. The failure, btw, means that your script is wrong, and tries to  
access a property that is not there.

On Wed, Jun 27, 2012 at 7:13 AM, Rauan Maemirov [rauan1987@gmail.com](mailto:rauan1987@gmail.com) wrote:

> Hi list. Is it possible to update docs with stored mvel script? I'm  
> getting exception
> 
> {  
> "error" : "ElasticSearchIllegalArgumentException[failed to execute  
> script]; nested: PropertyAccessException[[Error: unresolvable property or  
> identifier: updatedoc]\n[Near : {... updatedoc ....}]\n  
> ^\n[Line: 1, Column: 1]]; ",  
> "status" : 400  
> }
> 
> Update request looks like
> 
> curl -XPOST '[http://localhost:9200/test/docs/1/\_update?pretty=true](http://localhost:9200/test/docs/1/_update?pretty=true)' -d '{  
> "script": "updatedoc",  
> "lang": "mvel",  
> "params": {  
> ...  
> }
> 
> And my updatedoc.js is under elasticsearch/config/scripts/ directory.

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 27, 2012, 3:50pm UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/3 "2012-06-27T15:50:51Z")

</div>

Which extension should be used for mvel script files?  
Does stored scripts supports text indentation? The main reason for me to  
use it, it looks less ugly that 'all in one string'.  
And i don't understand, what could be wrong with it, it's exactly the same  
script that I've used in script 'all-in-one-string' and it worked ok.

Le mercredi 27 juin 2012 21:20:58 UTC+6, kimchy a écrit :

> Yes, you can, though setting the lang is not relevant when using scripts  
> that are registered on the node level, the language is detected based on  
> the extension of the file, in which case its javascript cause you call it  
> update.js. The failure, btw, means that your script is wrong, and tries to  
> access a property that is not there.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 27, 2012, 6:05pm UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/4 "2012-06-27T18:05:50Z")

</div>

The extension for mvel is .mvel. You can use stored scripts, not a problem.  
Hard to help without seeing the script.

On Wed, Jun 27, 2012 at 5:50 PM, Rauan Maemirov [rauan1987@gmail.com](mailto:rauan1987@gmail.com) wrote:

> Which extension should be used for mvel script files?  
> Does stored scripts supports text indentation? The main reason for me to  
> use it, it looks less ugly that 'all in one string'.  
> And i don't understand, what could be wrong with it, it's exactly the same  
> script that I've used in script 'all-in-one-string' and it worked ok.
> 
> Le mercredi 27 juin 2012 21:20:58 UTC+6, kimchy a écrit :
> 
> > Yes, you can, though setting the lang is not relevant when using scripts  
> > that are registered on the node level, the language is detected based on  
> > the extension of the file, in which case its javascript cause you call it  
> > update.js. The failure, btw, means that your script is wrong, and tries to  
> > access a property that is not there.

---

<div class="post-metadata">

**Author:** ![Rauan\_Maemirov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rauan_maemirov/32/826_2.png) [@Rauan\_Maemirov](https://discuss.elastic.co/u/Rauan_Maemirov)\
**Post date:** [June 28, 2012, 6:23am UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/5 "2012-06-28T06:23:43Z")

</div>

I changed extension, looks like now it defines correct lang and shows error.  
"error" : "ElasticSearchIllegalArgumentException[failed to execute script];  
nested: RuntimeException[cannot invoke method: size]; nested: ",

It's related to this:  
ctx.\_source.inventory.size()

Here's the script: [https://gist.github.com/f4253a84e0694eb6acaa](https://gist.github.com/f4253a84e0694eb6acaa)

inventory is an array of nested objects. (with inline script everything  
works right)

Le jeudi 28 juin 2012 00:05:50 UTC+6, kimchy a écrit :

> The extension for mvel is .mvel. You can use stored scripts, not a  
> problem. Hard to help without seeing the script.

---

<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, 3:22am UTC](https://discuss.elastic.co/t/update-api-with-stored-scripts/8236/6 "2017-07-06T03:22:13Z")

</div>


