Must_not in bool?

Hi,

Usecase : I want to delete all the documents that are not having certain id's .

Mappings:

"bookList": {
                  "properties": {
                     "bookname": {
                        "type": "string"
                     },
                     "bookId": {
                        "type": "long"
                     },
}

The content will be like this in each document : Some have inner lists let it be DOC1 :

"bookList": [
                  {
                     "bookname": "HITLER",
                     "bookId": 3163
                   },
                   {
                       "bookname": "MARTIAN", 
                       "bookId": 1210
                   }
                   ]

And some only one list like this Let it be DOC2

"bookList": [
                  {
                     "bookname": "WASHINGTON",
                     "bookId": 3163
                   }
                   ]

And another document DOC3:

 "bookList": [
                      {
                         "bookname": "SHELDON",
                         "bookId": 3163
                       },
                       {
                           "bookname": "MARVELS", 
                           "bookId": 1219
                       }
                       ]

I am using delete_by_query plugin in ES 2.4.0 to delete the documents that are NOT having bookId : 3163 using MUST_NOT in bool query . For inner lists documents(i.e.DOC1 & DOC3) it is not deleting them because MUST_NOT find's the exact term if the term is present in either of the inner lists then it is not deleting that document.

My Query is like this :

{
    "query" : {
    "bool" : {
        "must_not" : {
            "term" : {
        "bookList.bookId" :3163 
            }
    }
    }
}
}

The problem here is Must_not finds the exact term in a documents if it exists one time too it wont delete the documents (i.e.DOC1 & DOC3) . Is there any way possible to delete those documents since they are having other bookid's . Because i even tried writing a bool query should in must_not but it too didnt work.

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.