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


(Sisu Alexandru) #1

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


(Shay Banon) #2

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


(Sisu Alexandru) #3

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


(system) #4