# Question about Missing filter on nested fields

**URL:** <https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525>\
**Category:** Elasticsearch\
**Created:** [October 6, 2011, 8:10am UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525 "2011-10-06T08:10:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alheim](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alheim](https://discuss.elastic.co/u/alheim)\
**Post date:** [October 6, 2011, 8:10am UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/1 "2011-10-06T08:10:56Z")

</div>

Hello,

Imagine that we have a nested field adress : adress.street, adress.zipCode  
I cannot use a missing filter on adress :  
{  
"query": {  
"constant\_score": {  
"filter": {  
"missing": {  
"field": "adress"  
}  
}  
}  
}  
}

nor on sub-fields :  
{  
"query": {  
"constant\_score": {  
"filter": {  
"missing": {  
"field": "adress.zipCode"  
}  
}  
}  
}  
}

Any idea ?

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 6, 2011, 6:46pm UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/2 "2011-10-06T18:46:48Z")

</div>

You mean you are using nested mapping for adress? If so, you need to use  
nested filter (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-filter.html))  
or query (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)).

On Thu, Oct 6, 2011 at 10:10 AM, Alexandre Heimburger \<  
[ahb@bluekiwi-software.com](mailto:ahb@bluekiwi-software.com)\> wrote:

> Hello,
> 
> Imagine that we have a nested field adress : adress.street, adress.zipCode  
> I cannot use a missing filter on adress :  
> {  
> "query": {  
> "constant\_score": {  
> "filter": {  
> "missing": {  
> "field": "adress"  
> }  
> }  
> }  
> }  
> }
> 
> nor on sub-fields :  
> {  
> "query": {  
> "constant\_score": {  
> "filter": {  
> "missing": {  
> "field": "adress.zipCode"  
> }  
> }  
> }  
> }  
> }
> 
> Any idea ?
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![alheim](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alheim](https://discuss.elastic.co/u/alheim)\
**Post date:** [October 7, 2011, 7:18am UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/3 "2011-10-07T07:18:24Z")

</div>

I'm sorry but I'm not sure to understand. Actually I did not use any  
specific mapping. I just index the structure described in my post.

I've read and read and read again the documentation and I really don't get  
how to make the missing filter working for that structure. Can you post any  
example ?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 8, 2011, 6:40pm UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/4 "2011-10-08T18:40:44Z")

</div>

Can you post a sample document that you index?

On Fri, Oct 7, 2011 at 9:18 AM, Alexandre Heimburger \<  
[ahb@bluekiwi-software.com](mailto:ahb@bluekiwi-software.com)\> wrote:

> I'm sorry but I'm not sure to understand. Actually I did not use any  
> specific mapping. I just index the structure described in my post.
> 
> I've read and read and read again the documentation and I really don't get  
> how to make the missing filter working for that structure. Can you post any  
> example ?
> 
> Thanks a lot.

---

<div class="post-metadata">

**Author:** ![alheim](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@alheim](https://discuss.elastic.co/u/alheim)\
**Post date:** [October 10, 2011, 7:28am UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/5 "2011-10-10T07:28:54Z")

</div>

{  
"firstName" : "Alex",  
"lastName": "Heim",  
"adress" : {  
"zipCode": 92200,  
"street": "street of philadelphia"  
}  
}

Querying missing field on adress does not work (i.e : return all the  
entries)

Querying missing field on adress.zipCode works well.

I think I got the pattern. You can query on missing field if the field is  
not nested (i.e is a string, numerical).

Do you confirm ?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 12, 2011, 6:30pm UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/6 "2011-10-12T18:30:23Z")

</div>

No, you can't do missing on a json object, just on concrete fields (that get  
indexed).

On Mon, Oct 10, 2011 at 9:28 AM, Alexandre Heimburger \<  
[ahb@bluekiwi-software.com](mailto:ahb@bluekiwi-software.com)\> wrote:

> {  
> "firstName" : "Alex",  
> "lastName": "Heim",  
> "adress" : {  
> "zipCode": 92200,  
> "street": "street of philadelphia"  
> }  
> }
> 
> Querying missing field on adress does not work (i.e : return all the  
> entries)
> 
> Querying missing field on adress.zipCode works well.
> 
> I think I got the pattern. You can query on missing field if the field is  
> not nested (i.e is a string, numerical).
> 
> Do you confirm ?

---

<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 6, 2017, 3:52am UTC](https://discuss.elastic.co/t/question-about-missing-filter-on-nested-fields/5525/7 "2017-07-06T03:52:16Z")

</div>


