-
-
Save shinux/66aec77f2080942f7e57704d85062800 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