Average on boolean


(Champtar) #1

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


(Court Ewing) #2

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:

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


(Champtar) #3

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


(Court Ewing) #4

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!


(system) #5

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