# Must\_not not working as expected, elasticsearch5.5

**URL:** <https://discuss.elastic.co/t/must-not-not-working-as-expected-elasticsearch5-5/154274>\
**Category:** Elasticsearch\
**Created:** [October 27, 2018, 7:50am UTC](https://discuss.elastic.co/t/must-not-not-working-as-expected-elasticsearch5-5/154274 "2018-10-27T07:50:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shruti\_Mansinghka](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Shruti\_Mansinghka](https://discuss.elastic.co/u/Shruti_Mansinghka)\
**Post date:** [October 27, 2018, 7:50am UTC](https://discuss.elastic.co/t/must-not-not-working-as-expected-elasticsearch5-5/154274/1 "2018-10-27T07:50:37Z")

</div>

I have a nested type-\> documents inside applications. I want to retrieve the applications which do not contain the documents with document\_type 6.

{  
"query": {  
"bool": {  
"must\_not": [  
{  
"nested": {  
"path": "documents",  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"document\_type": 6  
}  
}  
]  
}  
}  
}  
}  
]  
}  
}  
}

This gives applications with document\_type 6 as well. Not sure if there's something wrong with the query.

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [October 29, 2018, 2:31pm UTC](https://discuss.elastic.co/t/must-not-not-working-as-expected-elasticsearch5-5/154274/2 "2018-10-29T14:31:36Z")

</div>

You need to provide the full path to the nested field: `documents.document_type`. Your query becomes:

```auto
{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "documents",
            "query": {
              "term": {
                "documents.document_type": 6
              }
            }
          }
        }
      ]
    }
  }
}

```

---

<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:** [November 26, 2018, 2:31pm UTC](https://discuss.elastic.co/t/must-not-not-working-as-expected-elasticsearch5-5/154274/3 "2018-11-26T14:31:37Z")

</div>

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