# Nested Query - Exclude parent document with nested query and must\_not/filter

**URL:** <https://discuss.elastic.co/t/nested-query-exclude-parent-document-with-nested-query-and-must-not-filter/115185>\
**Category:** Elasticsearch\
**Created:** [January 11, 2018, 10:25pm UTC](https://discuss.elastic.co/t/nested-query-exclude-parent-document-with-nested-query-and-must-not-filter/115185 "2018-01-11T22:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurav/32/26497_2.png) [@saurav](https://discuss.elastic.co/u/saurav)\
**Post date:** [January 11, 2018, 10:25pm UTC](https://discuss.elastic.co/t/nested-query-exclude-parent-document-with-nested-query-and-must-not-filter/115185/1 "2018-01-11T22:25:07Z")

</div>

Trying to exclude top level documents where one of the child documents doesn't match the query. For the example below, I'm trying to exclude all documents where one of it's nested jobs has `current: true`, and matches with the company name: Elastic. But since one of the nested job documents matches with current: false and company name: Elastic, this document is returned. I am using a nested query with a must match on company name and a filter where `current: false`. How can I make it so that the below document _is not_ returned?

```auto
          "name": "john doe",
          "jobs": [
            {
              "title": "Vice President",
              "current": true,
              "company": {
                "name": "Elastic"
              }
            },
            {
              "title": "CEO",
              "current": false,
               "company": {
                 "name": "Elastic"
              }

```

---

<div class="post-metadata">

**Author:** ![saurav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saurav/32/26497_2.png) [@saurav](https://discuss.elastic.co/u/saurav)\
**Post date:** [January 16, 2018, 4:37pm UTC](https://discuss.elastic.co/t/nested-query-exclude-parent-document-with-nested-query-and-must-not-filter/115185/2 "2018-01-16T16:37:24Z")

</div>

This answer helped: [https://stackoverflow.com/questions/48229388/elasticsearch-nested-query-exclude-parent-document](https://stackoverflow.com/questions/48229388/elasticsearch-nested-query-exclude-parent-document)

---

<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:** [February 13, 2018, 4:37pm UTC](https://discuss.elastic.co/t/nested-query-exclude-parent-document-with-nested-query-and-must-not-filter/115185/3 "2018-02-13T16:37:34Z")

</div>

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