I have documents containing nested tables in the following format :
{
"dataId": "dataIdentifier",
"versionId": "versionIdentifier",
"items": [
{
"obj1": "value1",
"obj2": "value2",
"obj3": "value3",
},
{
"obj1": "value4",
"obj2": "value5",
"obj3": "value6"
},
{
"obj1": "value7",
"obj2": "value8",
"obj3": "value9"
}
]
}
With "items" being of nested type. I want to delete one of the elements inside the "items" given than one of the object inside has a certain value. For instance it would be :
if (obj1 == "value4" & dataId == "dataIdentifier" & versionId == versionIdentifier) :
DELETE TABLE ENTRY
In this case I want to delete the second entry of "items". I tried to do it with update_by_query, and my attempt was :
q = {
"query": {
"match_all": {}
}
},
"script": {
"lang" : "painless",
"inline" : {if (ctx._source.dataId == item.dataId && ctx._source.versionId == item.versionId && ctx._source.items.obj1 == item.obj1) {ctx._source.items.remove()}}",
"params" : {
'dataFrame': [{
"dataId" : 'myDataIdList',
"versionId" : 'myVersionId',
"obj1" : 'myValue'
} ]
}
}
}
es.update_by_query(index=myindex, body=q)
But I do not know how to designate the concerned entry in the "ctx._source.items.remove()" argument. I took a look at the Elasticsearch documentation but could not find what I was looking for. Any help would be greatly appreciated.