Nested Query - Exclude parent document with nested query and must_not/filter

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?

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

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

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