Scripted field to get percentage


(shah) #1

Hello Team,
I am new to scripted field and facing issue in creating one. I have field called status which has multiple values like "pass", "fail", and few more. I want to create a scripted field to get pass percentage on daily basis and plot it. So basically want to do total number of pass/total number of status field on daily basis. Can someone help me or guide me where i can read for the solution?


(Chris Roberson) #2

I'm not sure a scripted field will help here. What does it look like so far? Can you just do a terms agg in a visualization over the status field?


(shah) #3

No its a string field basically so it does not show up in terms agg.


(Chris Roberson) #4

Can you use a scripted field to transform it to a number? pass = 2, fail = 1 or something?


(shah) #5

Yes i did like this for pass and fail value

Field name:--passtotal
if (doc['status.keyword'].value == 'pass') {return 1}

Field name:- failtotal
if (doc['status.keyword'].value == 'fail') {return 1}

but i dont know how i can do passtotal/passtotal+failtotal to get percentage


(Chris Roberson) #6

Pretty sure this is not supported right now.

The scripted field won't work because you don't have the context of the entire data set to calculate the necessary percentage and we don't have the ability to show percentages in a data table yet: https://github.com/elastic/kibana/issues/19489


(shah) #7

Got it. Will wait for enhancement. Thanks.


(system) #8

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