I just started with ES and still leaning the tricks of the trade!!! I need to replace/overwrite one of the fields of a nested object type. Here is the sample doc:
{
"name":"db_ref",
"ref_counter":[
{"ref_name":"test1","count":1},
{"ref_name":"test2","count":2},
{"ref_name":"test3","count":3}
]
}
Mapping for the above doc :
{
"settings": {
"mappings": {
"test_doc": {
"properties": {
"name": {
"type": "string"
},
"ref_count": {
"type": "nested",
"ref_name": "string",
"count": "long"
}
}
}
}
}
}
I need to update the count field value for a given ref_name. Eg, in the above case, if ref_name is "test1" I want the new count to be 500. I came up with the below painless script for changing the count value, it executes fine without any error but I dont see the value being updated.
curl -XPOST "http://localhost:9200/test_type/test_type/test_db/_update" -d '
{"script": "if (ctx._source.ref_counter.ref_name == cur_ref
&& ctx._source.ref_counter.count == cur_count)
{ctx._source.ref_counter.count = new_count };",
"params": {"cur_count": 1,"new_count": 500, "cur_ref": "test1"}}}'
Below is the response:
{"_index":"test_index","_type":"test_type","_id":"test_db","_version":2}
But when I see the document it still has the old values.
Can someone please help me in changing the count value to a new value.