I am working to dump and update the Elasticsearch data, I am able to properly dump the data but I am not able to update the records for example
when I do
GET test/users/3985882
I would get the following response
{
"_index": "test",
"_type": "users",
"_id": "3985882",
"_version": 1,
"found": true,
"_source": {
"gender": null,
"user_mixpanel_data": {
"event_name": "Detail",
"time": "2017-07-01 01:37:43 IST",
"email": "abc@gmail.com"
},
"email": "abc@gmail.com",
"user_invoices": [
{
"number": "54539",
"orders": [
{
"order_id": "54539C1"
}
]
}
]
}
}
Now when I try to update the nested object user_invoices and need to update this, I am trying the script from the following question asked on SO i.e. https://stackoverflow.com/questions/36589963/elasticsearchuse-script-to-update-nested-field
I modified the script according to my problem.
POST test/users/_update
{
"script": "def updated = false; ctx._source.user_invoices?.each { obj -> if (obj.number == item.number) { obj.number = item.new_number; updated = true;}; if (!updated) { ctx._source.user_invoices = ((ctx._source.user_invoices ?: []) + item)}",
"lang": "painless",
"params": {
"item": {
"number": "54539",
"new_number": "54540",
"order_id": "54539C1",
"new_order_id": "54539C2"
}
}
}
the above script gives me the following response
{
"_index": "test",
"_type": "users",
"_id": "_update",
"_version": 28,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": false
}
Here the response shows the query was successful, but when I again see the same record I do not get the updated response.
I also have asked this question on Stack Overflow , you can check this here: