Elastic Percentile Rank

I need to calculate the percentile rank of my client in a set of data when i apply a filter. For Instance when i apply a particular filter , my client might not fall in that dataset , but still i want my client to be included in the dataset and find the percentile of where he stands . In-short is it possible t override the percentile calculation of elastic search using scripting . Any suggestion on that front would be great.

I do not fully understand the requirement. Do you want to include all data in the percentile calculation independent from the filter used in the query?

1 Like

Thanks for your reply @spinscale.

Yes that is one of the requirement. As Elastic calculates the persentile by applying filter on the data, in one of the negative scenario case it is showing wrong percentile value over there. Can you please help ?

@spinscale for instance , i need to mark the percentile of my client data in a pool of data, I need to calculate percentile , including all data irrespective of the client data falling under the filter .

Eg : From a pool of 20 data , when i want to mark percentile for my client after applying a particular filter ( say age > 40) and my client does not fall into the filter criteria , still i want to include him calculating percentile. so , if 12 people satisfy the filter criteria , i want it to be 13 .

when you need to use all data, you can wrap the percentile aggregation with a global aggregation

@spinscale its not like i need to use all data , i want to include my client data , in all the dataset which i have got after filtering. so, out of 20 data , after applying filters i get 12 data ( in which my client data is excluded) i want to include my client data in it and do percentile calculation for my client.

maybe you can use a post_filter to filter your document further, alternatively just use a filter aggregation on top of the global one. Two requests could also be an option, as the aggregation only request could potentially be cached if it gets reused.