Scripting at Kibana visualization to achieve calculations on bucket aggregation count

Hello Elastic Team, :wave:

Elastic and Kibana version : v 8.4.2
configured on: Azure elastic cloud
We had one use case , where we wanted to calculate number of dropouts from each bucket aggregation.
Our application is designed to calculate number of dropouts on each steps.
Lets suppose, we have basic preference page where users need to follow 5 steps which are:
1st-PreferredJobs
2nd-Salary
3rd-Skills
4th-PreferredWorkLocation
5th-CreateProfile

My earlier requirement was below:
How can I calculate kibana aggregation count with each other to get the value by subtraction. For example I have 4 buckets, 10 value in 1st bucket , 5 value in 2nd bucket n so on. I want to subtract 1st bucket value with 2nd bucket value (10-5=5)
PreferredJobs events counts are 10
Salary events counts are 5

then number of dropout events at Salary page is 5 (10-5=5)
We wanted show this difference.

I have managed to get this calculation with below scipted field "salarypage_dropouts" ,

if (doc['Event_Name.keyword'].value=='PreferredJobs'){emit(1)}
 else if (doc['Event_Name.keyword'].value=='Salary'){emit(-1)}

Then using metric visulization (Metric sum of salarypage_dropouts) I'm getting dropout counts are 5.

1st requirement: Now, our requirement is to calculate unique users count who are not able to follow mentioned steps,
We want the count of unique users who Dropped at each step and earlier count was events counts , that was from same users multiple times.

Can you please help me to achieve this calculations.
FYR, Below is the bucket aggregation visualization I have created.

In above PreferredJobs events counts was 59 and PreferredWorkLocation events count was 37 , then events wise number of dropouts at PreferredWorkLocation are 59-37=22. we want 11-11=0(Unique user counts)

Also, 2nd requirement: We want to apply custom sort on each events buckets, as per my choice (no aphabetic order , no metric count wise order)
For example, whatever will be the count but I want to keep my event wise order.(1st-PreferredJobs
2nd-Salary
3rd-Skills
4th-PreferredWorkLocation
5th-CreateProfile)

Thank you in advance! :smiling_face:

Hello Team,

Anyone could help me with my use case? It would be very helpful If I can have some logics in my scripts here.

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