Must_not with exists query on nested object returns excluded field

Hi all,
I am querying using search API and tried a query using must_not exists to get documents where there is no list of emails in a group within a class. However, it still returns documents with email_list inside the group and class. The following is my query

{
	"query": {
		"bool": {
			"must_not": [
				{
					"exists": {
						"field": "class.group.email_list"
					}
				}
			]
		}
	}
}

My mapping related to the query is as follows

{
	"class": {
		"properties": {
			"id": {
				"type": "long"
			},
			...
			"status": {
				"type": "long"
			},
			"group": {
				"type": "nested",
				"properties": {
					"id": {
						"type": "long"
					},
					"email_list": {
						"type": "keyword"
					},
					...
				}
			}
		}
	}
}

I've also tried the following queries, which I found on StackOverflow to no avail

{
	"query": {
		"bool": {
			"must_not": [
				{
					"nested": {
						"path": "class.group",
						"query": {
							"exists": {
								"field": "email_list"
							}
						}
					}
				}
			]
		}
	}
}

I've also tried this query, however, it results in an error saying that the object "class" is not nested.

{
	"query": {
		"bool": {
			"must_not": [
				{
					"nested": {
						"path": "class",
						"query": {
							"exists": {
								"field": "group.email_list"
							}
						}
					}
				}
			]
		}
	}
}

How can I get documents where there is no email_list in a group within the class? Any help would be great...

Thanks a lot

I asked the same question in StackOverflow and got the answer as follows
src: kibana - Elasticsearch Must_not with exists query on nested object returns excluded field - Stack Overflow

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "class.group",
            "query": {
              "exists": {
                "field": "class.group.email_list"
              }
            }
          }
        }
      ]
    }
  }
}

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