Scripted field to get percentage

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?

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?

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

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

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

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

Got it. Will wait for enhancement. Thanks.

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