Created
April 16, 2012 12:04
-
-
Save alexsisu/2398248 to your computer and use it in GitHub Desktop.
ElasticSearch partial field update: remove element from array, does not work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT 'http://localhost:9200/testindex' -d '{ | |
"settings": | |
{ | |
"number_of_shards": 1, | |
"number_of_replicas": 0 | |
} | |
} | |
' | |
curl -XPUT 'http://localhost:9200/testindex/posting/_mapping' -d ' | |
{ "posting": { | |
"properties": | |
{ | |
"id": {"type": "long", "store": "yes"}, | |
"labels": {"type": "integer", "index_name": "label", "store": "yes"} | |
} | |
} | |
} | |
' | |
curl -XPOST 'http://localhost:9200/_bulk?pretty=true' -d ' | |
{"index" : { "_index" : "testindex", "_type" : "posting", "_id" : "1" }} | |
{"labels":[], "id":1} | |
' | |
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' | |
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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try this, it should work.
remember to enable the dynamic script first by put the follow line in your elasticsearch.yml: