# Average on boolean

**URL:** <https://discuss.elastic.co/t/average-on-boolean/70015>\
**Category:** Kibana\
**Created:** [December 26, 2016, 5:12pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015 "2016-12-26T17:12:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![champtar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/champtar/32/21937_2.png) [@champtar](https://discuss.elastic.co/u/champtar)\
**Post date:** [December 26, 2016, 5:12pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015/1 "2016-12-26T17:12:35Z")

</div>

Hi,

I have a is\_hit boolean in my docs, and would like to display the hit ratio in a data table or metric visualisation  
Is it possible? How?  
Basically it's the average of is\_hit where true == 100 and false == 0 but i can't do average on boolean fields, only on numbers

Regards  
Etienne

EDIT: i'm using ELK 5.1.1

---

<div class="post-metadata">

**Author:** ![Court](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/court/32/6640_2.png) [@Court](https://discuss.elastic.co/u/Court)\
**Post date:** [December 26, 2016, 5:48pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015/2 "2016-12-26T17:48:32Z")

</div>

I was able to do this with a scripted field. I didn't have a boolean handy, but using a numeric bytes field and the following painless script, I had a new `is_big` field that was either 0 or 100. I could then use that scripted field in a metrics agg:

```auto
return doc['bytes'].value > 10000 ? 100 : 0;

```

 ![](https://us1.discourse-cdn.com/elastic/original/2X/a/a6b65ebbb4240b0170ec6de73c35d625fd6098b8.png)

---

<div class="post-metadata">

**Author:** ![champtar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/champtar/32/21937_2.png) [@champtar](https://discuss.elastic.co/u/champtar)\
**Post date:** [December 27, 2016, 4:07pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015/3 "2016-12-27T16:07:31Z")

</div>

Thanks @Court  
I was worried that your solution was going to destroy performance, but this seams ok

---

<div class="post-metadata">

**Author:** ![Court](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/court/32/6640_2.png) [@Court](https://discuss.elastic.co/u/Court)\
**Post date:** [December 28, 2016, 7:50pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015/4 "2016-12-28T19:50:39Z")

</div>

It's good to be cautious when considering scripted fields as they will negatively impact performance when dealing with a large amount of data. I'm glad it works for your use case, though!

---

<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:** [January 25, 2017, 7:51pm UTC](https://discuss.elastic.co/t/average-on-boolean/70015/5 "2017-01-25T19:51:10Z")

</div>

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