Update api with stored scripts


(Rauan Maemirov) #1

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' -d '{
"script": "updatedoc",
"lang": "mvel",
"params": {
...
}

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


(Shay Banon) #2

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 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' -d '{
"script": "updatedoc",
"lang": "mvel",
"params": {
...
}

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


(Rauan Maemirov) #3

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.


(Shay Banon) #4

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 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.


(Rauan Maemirov) #5

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

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.


(system) #6