# Must\_not in bool?

**URL:** <https://discuss.elastic.co/t/must-not-in-bool/90767>\
**Category:** Elasticsearch\
**Created:** [June 25, 2017, 7:57pm UTC](https://discuss.elastic.co/t/must-not-in-bool/90767 "2017-06-25T19:57:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [June 25, 2017, 7:57pm UTC](https://discuss.elastic.co/t/must-not-in-bool/90767/1 "2017-06-25T19:57:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 23, 2017, 7:57pm UTC](https://discuss.elastic.co/t/must-not-in-bool/90767/2 "2017-07-23T19:57:54Z")

</div>

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