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

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).

"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.

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

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