# Difference between using nested type in query with must\_not

**URL:** <https://discuss.elastic.co/t/difference-between-using-nested-type-in-query-with-must-not/141194>\
**Category:** Elasticsearch\
**Created:** [July 23, 2018, 2:22pm UTC](https://discuss.elastic.co/t/difference-between-using-nested-type-in-query-with-must-not/141194 "2018-07-23T14:22:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Miller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/erik_miller/32/14913_2.png) [@Erik\_Miller](https://discuss.elastic.co/u/Erik_Miller)\
**Post date:** [July 23, 2018, 2:22pm UTC](https://discuss.elastic.co/t/difference-between-using-nested-type-in-query-with-must-not/141194/1 "2018-07-23T14:22:27Z")

</div>

I've come across a scenario where I am returning fewer results when using a nested query for accessing the nested object data vs just using a normal terms query.

With the nested query it returns documents that I want excluded.

```
        "must_not": [
          {
            "nested": {
              "path": "images",
              "filter": {
                "bool": {
                  "must": [
                    {
                      "terms": {
                        "images.type": [
                          "BANNER",
                          "BANNER-2",
                          "BANNER-LOGO",
                          "ICONIC"
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        ]

```

Without the nested query it works as expected.

```
    "must_not": [
      {
        "terms": {
          "images.type": [
            "BANNER",
            "BANNER-2",
            "BANNER-LOGO",
            "ICONIC"
          ]
        }
      } 

```

Any one know what 's going on here, I thought this logic would be identical. Basically we just want to return documents that don't have images of type BANNER, BANNER-2, BANNER-LOGO, or ICONIC.

---

<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:** [August 20, 2018, 2:22pm UTC](https://discuss.elastic.co/t/difference-between-using-nested-type-in-query-with-must-not/141194/2 "2018-08-20T14:22:35Z")

</div>

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