Partial update on a field, remove element from an array does not work

Hi,

Here's the gist: https://gist.github.com/2398248
Im adding elements into a field. Im trying to remove them from there. It
doesnt work.

curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels += label",
"params" : {
"label" : 5
}
}'

curl -XGET 'http://localhost:9200/testindex/posting/1'

This one does not work:
curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels -= label",
"params" : {
"label" : 5
}
}'

#result is {"error":"ElasticSearchIllegalArgumentException[failed to
execute script]; nested: StringIndexOutOfBoundsException[String index out
of range: -1]; ","status":400}

Am I using it incorrectly?

Tnx in advance,

Alex

Heya,

I chased it down, and it seems like its a problem with the list that has
remove by an index (integer) and an object (equality). Forcing it to use
the remove with object works:

curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels.remove((Object) label);",
"params" : {
"label" : 5
}
}'

On Mon, Apr 16, 2012 at 3:07 PM, Sisu Alexandru sisu.eugen@gmail.comwrote:

Hi,

Here's the gist: ElasticSearch partial field update: remove element from array, does not work · GitHub
Im adding elements into a field. Im trying to remove them from there. It
doesnt work.

curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels += label",
"params" : {
"label" : 5
}
}'

curl -XGET 'http://localhost:9200/testindex/posting/1'

This one does not work:
curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels -= label",
"params" : {
"label" : 5
}
}'

#result is {"error":"ElasticSearchIllegalArgumentException[failed to
execute script]; nested: StringIndexOutOfBoundsException[String index out
of range: -1]; ","status":400}

Am I using it incorrectly?

Tnx in advance,

Alex

Tnx !:slight_smile:

On Thu, Apr 19, 2012 at 3:18 PM, Shay Banon kimchy@gmail.com wrote:

Heya,

I chased it down, and it seems like its a problem with the list that has
remove by an index (integer) and an object (equality). Forcing it to use
the remove with object works:

curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels.remove((Object) label);",
"params" : {
"label" : 5
}
}'

On Mon, Apr 16, 2012 at 3:07 PM, Sisu Alexandru sisu.eugen@gmail.comwrote:

Hi,

Here's the gist: ElasticSearch partial field update: remove element from array, does not work · GitHub
Im adding elements into a field. Im trying to remove them from there. It
doesnt work.

curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels += label",
"params" : {
"label" : 5
}
}'

curl -XGET 'http://localhost:9200/testindex/posting/1'

This one does not work:
curl -XPOST 'http://localhost:9200/testindex/posting/1/_update' -d '{
"script" : "ctx._source.labels -= label",
"params" : {
"label" : 5
}
}'

#result is {"error":"ElasticSearchIllegalArgumentException[failed to
execute script]; nested: StringIndexOutOfBoundsException[String index out
of range: -1]; ","status":400}

Am I using it incorrectly?

Tnx in advance,

Alex