# Return all the document missing some certain key (of type nested in the mapping)

**URL:** <https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128>\
**Category:** Elasticsearch\
**Created:** [November 27, 2024, 9:17am UTC](https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128 "2024-11-27T09:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bahnasawy](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bahnasawy](https://discuss.elastic.co/u/bahnasawy)\
**Post date:** [November 27, 2024, 9:17am UTC](https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128/1 "2024-11-27T09:17:21Z")

</div>

I have a document of this structure  
"\_source":  
{"id":1 ,  
"myNestedField" :  
[  
{"nested\_id":"u71","Name":"ABC"} ,  
{"nested\_id":"op90","Name":"EG"}  
]  
}  
The type of the nested\_id in the mapping is nested  
what i want to retrieve is to get all the documents missing the myNestedField key  
and example document that i want to retrieve is

"\_source":  
{"id":1}  
Please help

---

<div class="post-metadata">

**Author:** ![turtle](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@turtle](https://discuss.elastic.co/u/turtle)\
**Post date:** [November 27, 2024, 11:33am UTC](https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128/2 "2024-11-27T11:33:49Z")

</div>

You could try the below to get all doc with missing field or missing value.

```auto
GET /my_index/posts/_search
{
    "query" : {
        "constant_score" : {
            "filter": {
                "missing" : { "field" : "tags" }
            }
        }
    }
}

```

Ref: [Dealing with Null Values | Elasticsearch: The Definitive Guide [2.x] | Elastic](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)

---

<div class="post-metadata">

**Author:** ![bahnasawy](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bahnasawy](https://discuss.elastic.co/u/bahnasawy)\
**Post date:** [November 27, 2024, 11:54am UTC](https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128/3 "2024-11-27T11:54:16Z")

</div>

First Thank you for you help  
but it returns this error

```auto
  "error" : {
    "root_cause" : [
      {
        "type" : "parsing_exception",
        "reason" : "unknown query [missing]",
        "line" : 5,
        "col" : 28
      }
    ],
    "type" : "parsing_exception",
    "reason" : "unknown query [missing]",
    "line" : 5,
    "col" : 28,
    "caused_by" : {
      "type" : "named_object_not_found_exception",
      "reason" : "[5:28] unknown field [missing]"
    }
  },
  "status" : 400
}

```

---

<div class="post-metadata">

**Author:** ![bahnasawy](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bahnasawy](https://discuss.elastic.co/u/bahnasawy)\
**Post date:** [November 28, 2024, 7:17pm UTC](https://discuss.elastic.co/t/return-all-the-document-missing-some-certain-key-of-type-nested-in-the-mapping/371128/4 "2024-11-28T19:17:49Z")

</div>

My dear this is the solution  
GET my-index-000001/\_search

```auto
{
  "query": {
    "bool": {
      "must_not": {
        "nested": {
          "path": "myNestedField",
          "query": {
            "exists": {
              "field": "myNestedField"
            }
          }
        }
      }
    }
  }
}

```
