In trying to keep the update by query simple, I would like to use a search template for the query part. Updates are being made to matching nested objects so the script & query pieces are verbose like:
{
"script": {
"inline" : "for (int i = 0; i < ctx._source['Items'].length; ++i) { if (ctx._source['Items'][i].id == params.id) { for (entry in params.changes.entrySet()) { ctx._source['Items'][i][entry.getKey()] = entry.getValue() } } }",
"lang" : "painless",
"params": {
"id": "a7f168ce207080641b87098708433c4b",
"changes" : {
"Key0": "val00",
"Key1": "val01",
"Key2": "val02",
"Key3": "val03",
}
}
},
"query": {
"bool": {
"filter": {
"nested": {
"path": "Items",
"query": {
"bool": {
"filter": [{
"script" : {
"script" : {
"inline": "doc['Items.id'].value == params.id",
"lang": "painless",
"params": {
"id": "a7f168ce207080641b87098708433c4b"
}
}
}
}]
}
}
}
}
}
}
}
There are 3 ways this can hopefully be simplified
- first replace the inline script with a file. Straightforward.
- second, replace the query part to engage a search template. ???
- third, the 'params' object is being specified twice once in the update part and again in the query part, Can we just use one 'params' object? ???
Any ideas on 2 & 3 ?