# Find doucment with blank nested field

**URL:** <https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219>\
**Category:** Elasticsearch\
**Created:** [October 29, 2015, 7:12am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219 "2015-10-29T07:12:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagdish\_nasit](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jagdish\_nasit](https://discuss.elastic.co/u/jagdish_nasit)\
**Post date:** [October 29, 2015, 7:12am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/1 "2015-10-29T07:12:20Z")

</div>

Hi, I have nested property in my index document. I want to find all documents where nested field is blank.  
example: I am indexing below document, how can I search for document where contact is not available ?

1. {"Name": John, "contact": [{"office": 1234, "home":2345 }] }
2. {"Name": Tom }

Thanks !!!

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [October 29, 2015, 9:08am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/2 "2015-10-29T09:08:35Z")

</div>

I think the exits/missing filters might help you here. To quote from the documentation at [https://www.elastic.co/guide/en/elasticsearch/guide/current/\_dealing\_with\_null\_values.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/_dealing_with_null_values.html)

When dealing with null values "The first tool in your arsenal is the exists filter. This filter will return documents that have any value in the specified field. [...] The missing filter is essentially the inverse of exists: it returns documents where there is no value for a particular field. [...] The exists and missing filters also work on inner objects, not just core types."

```
DELETE index

PUT index/type/1 {
    "Name": "John", "contact": [{"office": "1234", "home":"2345" }] 
}

PUT index/type/2 {
  "Name": "Tom" 
}

GET index/_search {
    "query": {
        "missing" : { "field" : "contact" }
    }
}

```

Hope this helps you,

Isabel

---

<div class="post-metadata">

**Author:** ![jagdish\_nasit](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jagdish\_nasit](https://discuss.elastic.co/u/jagdish_nasit)\
**Post date:** [October 30, 2015, 10:46am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/3 "2015-10-30T10:46:09Z")

</div>

@mainec, I have tried with missing and its working fine if field is normal field. In my case contact in nested property, when I try the same query, its giving all records. Below is the query I am using, Am I doing anything wrong ?

POST index/\_search  
{  
"query" : {  
"filtered" : {  
"filter": {  
"missing" : { "field" : "contact" }  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [October 30, 2015, 10:53am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/4 "2015-10-30T10:53:16Z")

</div>

> [@jagdish\_nasit](#):
>
> In my case contact in nested property

I see - I naively assumed you were simply putting the document you supplied to the index and relied on automatic mappings. Seems like you supplied an explicit mapping beforehand then, right?

I think the information on the following github issue might help you: [Deprecate the `missing` query in favour of a negated `exists` query · Issue #14112 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/14112)

Hope this helps,  
Isabel

---

<div class="post-metadata">

**Author:** ![jagdish\_nasit](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jagdish\_nasit](https://discuss.elastic.co/u/jagdish_nasit)\
**Post date:** [October 30, 2015, 11:04am UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/5 "2015-10-30T11:04:44Z")

</div>

Thanks @mainec, Yes I applied explicit mapping. Seems this is know issue.

---

<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:** [July 5, 2017, 11:41pm UTC](https://discuss.elastic.co/t/find-doucment-with-blank-nested-field/33219/6 "2017-07-05T23:41:42Z")

</div>


