# Correct way to get Not Exists or Exists and empty fields Query for multiple level of nested properties

**URL:** <https://discuss.elastic.co/t/correct-way-to-get-not-exists-or-exists-and-empty-fields-query-for-multiple-level-of-nested-properties/323903>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [January 25, 2023, 9:39am UTC](https://discuss.elastic.co/t/correct-way-to-get-not-exists-or-exists-and-empty-fields-query-for-multiple-level-of-nested-properties/323903 "2023-01-25T09:39:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Kostaev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/denis_kostaev/32/116371_2.png) [@Denis\_Kostaev](https://discuss.elastic.co/u/Denis_Kostaev)\
**Post date:** [January 25, 2023, 9:39am UTC](https://discuss.elastic.co/t/correct-way-to-get-not-exists-or-exists-and-empty-fields-query-for-multiple-level-of-nested-properties/323903/1 "2023-01-25T09:39:31Z")

</div>

Hello,  
I have a mapping with the multiple level of nested properties. I'm trying to get Not Exists (not  
mapped) fields on 3 lvl or Exists and empty (empty string or null values).

```auto
"mappings": {
        "properties": {
            "id_1lvl" : {
                "type": "integer"
            },
            "type_1lvl": {
                "type": "keyword"
            },
            "name_1lvl": {
                "type": "keyword"
            },
            "lists_1lvl" : {
                "type" : "nested",
                "properties": {
                    "id_list_2lvl": {
                        "type": "integer"
                    },
                    "name_list_2lvl": {
                        "type": "keyword"
                    },
                    "user_2lvl": {
                        "type": "nested",
                        "dynamic": false,
                        "properties": {
                            "id_3lvl": {
                                "type": "integer"
                            },
                            "name_3lvl": {
                                "type": "keyword"
                            },
                            "type_3lvl": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            }
        }
    }

```

So I've got this query and it works for not exists (must\_not query for example when user\_2lvl or type\_3lvl are not mapped at all) fields but I need to implement OR exists and empty query along with and cannot find examples. Please help on that.

```auto
GET root/_search
    {
      "query": {
        "bool": {
          "must_not": [
            {
              "nested": {
                "path": "lists_1lvl.user_2lvl",
                "query": {
                  "exists": {
                    "field": "lists_1lvl.user_2lvl.type_3lvl"
                  }
                }
              }
            }
          ]
        }
      }
    }

```

---

<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 22, 2023, 9:39am UTC](https://discuss.elastic.co/t/correct-way-to-get-not-exists-or-exists-and-empty-fields-query-for-multiple-level-of-nested-properties/323903/2 "2023-02-22T09:39:53Z")

</div>

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