# Null handing in facets/filters

**URL:** <https://discuss.elastic.co/t/null-handing-in-facets-filters/11006>\
**Category:** Elasticsearch\
**Created:** [March 4, 2013, 11:47pm UTC](https://discuss.elastic.co/t/null-handing-in-facets-filters/11006 "2013-03-04T23:47:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [March 4, 2013, 11:47pm UTC](https://discuss.elastic.co/t/null-handing-in-facets-filters/11006/1 "2013-03-04T23:47:56Z")

</div>

It would be nice if we could use null value in term/terms filters and  
facets as indicator we want to filter/facet on missing values

for example following filter will return docs with country == canada or  
blank (bool of terms and missing filter)

terms:{  
country:['CANADA', null]  
}

While it could easily be done combining terms and missing filters it is a  
nice shortcut  
More importantly in facet\_filter null will be acting as a first class  
citizen allowing us to get stats using terms\_stats facets for missing filed  
values

But the truth is that I would not be considering the functionality above if  
terms\_stats facet would have been consistent in calculating stats for  
"missing" and "other" just like terms facet does with counts but  
unfortunately it completely disregards them. I was working around it by  
using statistical facet in the same query and using it to calculate "other

- missing" as difference between its total and sum of the total of each  
term produced by my terms\_stats facets. Unfortunately it does not let me  
distinguish between "missing" and "other" which is very important for us to  
produce consistent and complete charts. If use facet\_filter would give me  
stats for null I could have combined terms\_stats query on unfiltered terms  
with the same facet with facet\_filter for null value 🙂 It is ugly but so  
far I have not come up with any approach to calculate "missing" and "other"  
stats in terms\_stats facet

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:48am UTC](https://discuss.elastic.co/t/null-handing-in-facets-filters/11006/2 "2017-07-06T02:48:26Z")

</div>


