# Terms facet to include item where term is missing

**URL:** <https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799>\
**Category:** Elasticsearch\
**Created:** [January 17, 2011, 11:51pm UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799 "2011-01-17T23:51:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmosafi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmosafi/32/3280_2.png) [@nmosafi](https://discuss.elastic.co/u/nmosafi)\
**Post date:** [January 17, 2011, 11:51pm UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/1 "2011-01-17T23:51:22Z")

</div>

Say I have two documents like so:

{ "field1": "hello", "field2": "world" }  
{ "field1": "moo" }

And I run a terms facet on field2.

It would give me count 1 for "world" but I would also want a count of  
1 for null. Is this possible to achieve this somehow?

(Note: all fields are set to non\_analysed in the dynamic\_mapping.json)

Thanks  
Neil

---

<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:** [January 18, 2011, 12:21am UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/2 "2011-01-18T00:21:22Z")

</div>

Sure, quite simple to implement, can you open a feature request?  
On Tuesday, January 18, 2011 at 1:51 AM, Neil Mosafi wrote:

> Say I have two documents like so:
> 
> { "field1": "hello", "field2": "world" }  
> { "field1": "moo" }
> 
> And I run a terms facet on field2.
> 
> It would give me count 1 for "world" but I would also want a count of  
> 1 for null. Is this possible to achieve this somehow?
> 
> (Note: all fields are set to non\_analysed in the dynamic\_mapping.json)
> 
> Thanks  
> Neil

---

<div class="post-metadata">

**Author:** ![nmosafi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmosafi/32/3280_2.png) [@nmosafi](https://discuss.elastic.co/u/nmosafi)\
**Post date:** [January 18, 2011, 6:15pm UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/3 "2011-01-18T18:15:26Z")

</div>

Yep, here is it

> <https://github.com/elastic/elasticsearch/issues/632>
>
> Say I have two documents like so:
> 
> { "field1": "hello", "field2": "world" }
> …{ "field1": "moo" }
> 
> And I run a terms facet on field2.
> 
> It would give me count 1 for "world" but I would also want a count of 1 for null.
> 
> (Note: all fields are set to non\_analysed in the dynamic\_mapping.json)

Cheers

On Jan 18, 12:21 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Sure, quite simple to implement, can you open a feature request?
> 
> On Tuesday, January 18, 2011 at 1:51 AM, Neil Mosafi wrote:
> 
> > Say I have two documents like so:
> 
> > { "field1": "hello", "field2": "world" }  
> > { "field1": "moo" }
> 
> > And I run a terms facet on field2.
> 
> > It would give me count 1 for "world" but I would also want a count of  
> > 1 for null. Is this possible to achieve this somehow?
> 
> > (Note: all fields are set to non\_analysed in the dynamic\_mapping.json)
> 
> > Thanks  
> > Neil

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [January 19, 2011, 2:26am UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/4 "2011-01-19T02:26:00Z")

</div>

Looks like this was just added, sweet 🙂

Curious, will this functionality treat all the following the same for  
field2?  
{ "field1": "moo" }  
{ "field1": "moo", "field2": null }  
{ "field1": "moo", "field2": "" }

Thanks!

On Jan 18, 11:15 am, Neil Mosafi [nmos...@gmail.com](mailto:nmos...@gmail.com) wrote:

> Yep, here is it
> 
> [Terms Facet: Add option include counts where term is missing · Issue #632 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/632)
> 
> Cheers
> 
> On Jan 18, 12:21 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Sure, quite simple to implement, can you open a feature request?
> 
> > On Tuesday, January 18, 2011 at 1:51 AM, Neil Mosafi wrote:
> > 
> > > Say I have two documents like so:
> 
> > > { "field1": "hello", "field2": "world" }  
> > > { "field1": "moo" }
> 
> > > And I run a terms facet on field2.
> 
> > > It would give me count 1 for "world" but I would also want a count of  
> > > 1 for null. Is this possible to achieve this somehow?
> 
> > > (Note: all fields are set to non\_analysed in the dynamic\_mapping.json)
> 
> > > Thanks  
> > > Neil

---

<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:** [January 19, 2011, 9:50am UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/5 "2011-01-19T09:50:19Z")

</div>

Yea, though null values are generally better to use than empty strings.  
On Wednesday, January 19, 2011 at 4:26 AM, Paul wrote:

> Looks like this was just added, sweet 🙂
> 
> Curious, will this functionality treat all the following the same for  
> field2?  
> { "field1": "moo" }  
> { "field1": "moo", "field2": null }  
> { "field1": "moo", "field2": "" }
> 
> Thanks!
> 
> On Jan 18, 11:15 am, Neil Mosafi [nmos...@gmail.com](mailto:nmos...@gmail.com) wrote:
> 
> > Yep, here is it
> > 
> > [Terms Facet: Add option include counts where term is missing · Issue #632 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/issue/632)
> > 
> > Cheers
> > 
> > On Jan 18, 12:21 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Sure, quite simple to implement, can you open a feature request?
> > 
> > > On Tuesday, January 18, 2011 at 1:51 AM, Neil Mosafi wrote:
> > > 
> > > > Say I have two documents like so:
> > 
> > > > { "field1": "hello", "field2": "world" }  
> > > > { "field1": "moo" }
> > 
> > > > And I run a terms facet on field2.
> > 
> > > > It would give me count 1 for "world" but I would also want a count of  
> > > > 1 for null. Is this possible to achieve this somehow?
> > 
> > > > (Note: all fields are set to non\_analysed in the dynamic\_mapping.json)
> > 
> > > > Thanks  
> > > > Neil

---

<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, 4:13am UTC](https://discuss.elastic.co/t/terms-facet-to-include-item-where-term-is-missing/3799/6 "2017-07-06T04:13:33Z")

</div>


