Skip to content

Instantly share code, notes, and snippets.

@shinux
Forked from alexsisu/partial_update_maybe_issue
Created November 21, 2016 05:37
Show Gist options
  • Save shinux/66aec77f2080942f7e57704d85062800 to your computer and use it in GitHub Desktop.
Save shinux/66aec77f2080942f7e57704d85062800 to your computer and use it in GitHub Desktop.
ElasticSearch partial field update: remove element from array, does not work
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