How to rank bucket sort results?

I am creating a leaderboard query in elastic search, I have documents with parent-child relationship,
Parent Doc: Player
Child Doc: Team
A player can be in multiple teams.

I am calculating total score for each team and sorting the results using bucket sort, and I am getting correct sorted results.

i want to get a rank of each team in sorted results, for example in a 1000 teams totals results in each bucket value i should get a key something like Rank: 1 which is a index of that value in 1000 sorted results;

Here is my current attempt:

{ "size": 0, "query": { "bool": { "must": [ { "term": { "type": "contest_teams" } }, { "term": { "challenge_id": 212 } } ] } }, "aggs": { "team": { "terms": { "field": "user_id" }, "aggs": { "team_score": { "parent": { "type": "team_player" }, "aggs": { "total_points": { "sum": { "field": "points" } } } }, "team_points_bucket_sort": { "bucket_sort": { "sort": [ { "team_score.total_points": { "order": "desc" } } ], "size": 2, "from": 0 } } } } } }

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