# Best way of faceting on boolean field

**URL:** <https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511>\
**Category:** Elasticsearch\
**Created:** [January 26, 2013, 1:25am UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511 "2013-01-26T01:25:10Z")\
**Posts on this page:** 5\
**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:** [January 26, 2013, 1:25am UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511/1 "2013-01-26T01:25:10Z")

</div>

Helllo,

When faceting on boolean field by default ES uses T and F for values. I  
would prefer Yes, No, N/A (when it is blank) but I do not want to pollute  
my source json substituting boolean for Yes, No, N/A string and then having  
to deal with the text when consuming source data. (there are quite a few of  
boolean fields I need to support) Of course I can have my UI translate T  
and F to and from Yes, No, N/A but it woul dbe nice if I did not have to do  
it plus I want to be able to facet/filter on N/A for missing true/false  
values which plain faceting on boolean won't do (well it will give me  
missing but filtering on it will require filtering on not(true or false)).  
I was wondering if there is an elegant solution for it with multifield  
mapping. I know it could solve n/a issue since mapping allows to specify  
default value for empty json properties but I will need to change mapping  
from boolean to string and I do not know how to translate boolean to Yes,  
No, N/A. Use scripting?

Thank you,  
Alex

--

---

<div class="post-metadata">

**Author:** ![Kay\_Ropke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kay_ropke/32/2424_2.png) [@Kay\_Ropke](https://discuss.elastic.co/u/Kay_Ropke)\
**Post date:** [January 26, 2013, 10:06am UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511/2 "2013-01-26T10:06:42Z")

</div>

Hi!

For a patch and workaround please see [Facet value of boolean mapped fields should be "true" or "false" · Issue #2462 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2462)

Cheers,  
-k

On Jan 26, 2013, at 2:25 AM, AlexR [roytmana@gmail.com](mailto:roytmana@gmail.com) wrote:

> Helllo,
> 
> When faceting on boolean field by default ES uses T and F for values. I would prefer Yes, No, N/A (when it is blank) but I do not want to pollute my source json substituting boolean for Yes, No, N/A string and then having to deal with the text when consuming source data. (there are quite a few of boolean fields I need to support) Of course I can have my UI translate T and F to and from Yes, No, N/A but it woul dbe nice if I did not have to do it plus I want to be able to facet/filter on N/A for missing true/false values which plain faceting on boolean won't do (well it will give me missing but filtering on it will require filtering on not(true or false)). I was wondering if there is an elegant solution for it with multifield mapping. I know it could solve n/a issue since mapping allows to specify default value for empty json properties but I will need to change mapping from boolean to string and I do not know how to translate boolean to Yes, No, N/A. Use scripting?
> 
> ## Thank you, Alex

--

---

<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:** [January 26, 2013, 4:20pm UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511/3 "2013-01-26T16:20:08Z")

</div>

Thanks Kay,

As far as needing to facet on true/false/null what's the typical approach?  
use facet.\_missing for count and "not include true and false" filter?  
Is there a better technique of filtering on missing/null values in case of  
boolean in in general case of string tokens?

Thank you,  
Alex

On Saturday, January 26, 2013 5:06:42 AM UTC-5, Kay Röpke wrote:

> Hi!
> 
> For a patch and workaround please see  
> [Facet value of boolean mapped fields should be "true" or "false" · Issue #2462 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2462)
> 
> Cheers,  
> -k
> 
> On Jan 26, 2013, at 2:25 AM, AlexR \<[royt...@gmail.com](mailto:royt...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> Helllo,
> 
> When faceting on boolean field by default ES uses T and F for values. I  
> would prefer Yes, No, N/A (when it is blank) but I do not want to pollute  
> my source json substituting boolean for Yes, No, N/A string and then having  
> to deal with the text when consuming source data. (there are quite a few of  
> boolean fields I need to support) Of course I can have my UI translate T  
> and F to and from Yes, No, N/A but it woul dbe nice if I did not have to do  
> it plus I want to be able to facet/filter on N/A for missing true/false  
> values which plain faceting on boolean won't do (well it will give me  
> missing but filtering on it will require filtering on not(true or false)).  
> I was wondering if there is an elegant solution for it with multifield  
> mapping. I know it could solve n/a issue since mapping allows to specify  
> default value for empty json properties but I will need to change mapping  
> from boolean to string and I do not know how to translate boolean to Yes,  
> No, N/A. Use scripting?
> 
> Thank you,  
> Alex
> 
> --

--

---

<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:** [January 26, 2013, 4:23pm UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511/4 "2013-01-26T16:23:12Z")

</div>

Well found  
it [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.html)

On Saturday, January 26, 2013 11:20:08 AM UTC-5, AlexR wrote:

> Thanks Kay,
> 
> As far as needing to facet on true/false/null what's the typical approach?  
> use facet.\_missing for count and "not include true and false" filter?  
> Is there a better technique of filtering on missing/null values in case of  
> boolean in in general case of string tokens?
> 
> Thank you,  
> Alex
> 
> On Saturday, January 26, 2013 5:06:42 AM UTC-5, Kay Röpke wrote:
> 
> > Hi!
> > 
> > For a patch and workaround please see  
> > [Facet value of boolean mapped fields should be "true" or "false" · Issue #2462 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2462)
> > 
> > Cheers,  
> > -k
> > 
> > On Jan 26, 2013, at 2:25 AM, AlexR [royt...@gmail.com](mailto:royt...@gmail.com) wrote:
> > 
> > Helllo,
> > 
> > When faceting on boolean field by default ES uses T and F for values. I  
> > would prefer Yes, No, N/A (when it is blank) but I do not want to pollute  
> > my source json substituting boolean for Yes, No, N/A string and then having  
> > to deal with the text when consuming source data. (there are quite a few of  
> > boolean fields I need to support) Of course I can have my UI translate T  
> > and F to and from Yes, No, N/A but it woul dbe nice if I did not have to do  
> > it plus I want to be able to facet/filter on N/A for missing true/false  
> > values which plain faceting on boolean won't do (well it will give me  
> > missing but filtering on it will require filtering on not(true or false)).  
> > I was wondering if there is an elegant solution for it with multifield  
> > mapping. I know it could solve n/a issue since mapping allows to specify  
> > default value for empty json properties but I will need to change mapping  
> > from boolean to string and I do not know how to translate boolean to Yes,  
> > No, N/A. Use scripting?
> > 
> > Thank you,  
> > Alex
> > 
> > --

--

---

<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:54am UTC](https://discuss.elastic.co/t/best-way-of-faceting-on-boolean-field/10511/5 "2017-07-06T02:54:30Z")

</div>


