# Aggregation on Boolean Fields

**URL:** https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790
**Category:** Kibana
**Created:** [May 22, 2018, 11:03am UTC](https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790 "2018-05-22T11:03:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![siddharth\_jain](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@siddharth\_jain](https://discuss.elastic.co/u/siddharth_jain)
#### Post date: [May 22, 2018, 11:03am UTC](https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790/1 "2018-05-22T11:03:43Z")

</div>

To save space I want to convert one field to boolean type.

The mapping of the index is-

> {  
> "siddharth-03": {  
> "mappings": {  
> "\_doc": {  
> "properties": {  
> "age": {  
> "type": "boolean"  
> }  
> }  
> }  
> }  
> }  
> }

I can write a query on elasticsearch to give me the addition of this boolean field in its bucket.

> GET siddharth-03/\_search  
> {  
> "aggs": {  
> "NAME": {  
> "sum": {  
> "field": "age"  
> }  
> }  
> }  
> }

This results in the correct aggregation value-

> {  
> "took": 1,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "skipped": 0,  
> "failed": 0  
> },  
> "hits": {  
> "total": 3,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "siddharth-03",  
> "\_type": "\_doc",  
> "\_id": "2",  
> "\_score": 1,  
> "\_source": {  
> "age": "true"  
> }  
> },  
> {  
> "\_index": "siddharth-03",  
> "\_type": "\_doc",  
> "\_id": "1",  
> "\_score": 1,  
> "\_source": {  
> "age": "true"  
> }  
> },  
> {  
> "\_index": "siddharth-03",  
> "\_type": "\_doc",  
> "\_id": "3",  
> "\_score": 1,  
> "\_source": {  
> "age": "false"  
> }  
> }  
> ]  
> },  
> "aggregations": {  
> "NAME": {  
> "value": 2,  
> "value\_as\_string": "true"  
> }  
> }  
> }

When I want to add an aggregation on this boolean field in kibana, it shows me that the boolean field is not a compatible field for aggregations. How can I sum over this field in kibana?

---

<div class="post-metadata">

### Author: ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)
#### Post date: [May 22, 2018, 2:30pm UTC](https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790/2 "2018-05-22T14:30:08Z")

</div>

sum aggregation only works on numeric fields. you could use a scripted field to convert your boolean value to numeric, if you wanted to trade space for performance ... i don't think that's a good idea however ...

you can however use count and set a filter to age:true if you want to count your documents where count is true (instead of using a sum on `age` where age can only be 1 or 0

---

<div class="post-metadata">

### Author: ![siddharth\_jain](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@siddharth\_jain](https://discuss.elastic.co/u/siddharth_jain)
#### Post date: [May 23, 2018, 12:30pm UTC](https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790/3 "2018-05-23T12:30:56Z")

</div>

To save space, we require 1 bit numeric datatype to perform aggregations, but they are not available. Using filters is slower than sum aggregations. Why doesnt elasticsearch support 1 bit numeric datatype

---

<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: [June 20, 2018, 12:31pm UTC](https://discuss.elastic.co/t/aggregation-on-boolean-fields/132790/4 "2018-06-20T12:31:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
