Given the document
curl -XPUT 'localhost:9200/test/me/here' -d '{
"top" : [
{ "searchkey" : "change"},
{ "searchkey" : "keep"}
]
}'
I need an update query that will add new field to sub-document with searchkey
equal to change
and will keep any other sub-document. The expected result is:
{
"top" : [
{ "searchkey" : "change", "newfield" : "newvalue"},
{ "searchkey" : "keep"}
]
}
To update nested document by index, run:
curl -XPOST 'localhost:9200/test/me/here/_update' -d '{
"script" : "ctx._source.top[0].newfield = v",
"params" : {
"v" : "newvalue"
}
}'