0

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.

1
  • Alright so conceptually, I must update the entire document but to achieve this, is it possible with the update by query ? And if yes how can I delete an element of a nested array based on the content of that element ? Commented Jan 11, 2019 at 16:10

1 Answer 1

0

With update by query you can't remove "a field", you can replace it, for that, you can update it with others two values ​​you want to mantain or delete the document and index a new with that two values

Sign up to request clarification or add additional context in comments.

1 Comment

Based on the following link I am pretty sure I can : discuss.elastic.co/t/… . My question remains how is this achievable in this precise case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.