How to sort query result by sum of a field?


(Ali.Houshy) #1

Hi...
I have an index with name "user_activity" in elastic and a query that get all of result, now I want to sort my result from it by sum of coin fields of every user, this means that users should be sort by sum(coin) desc to find best three of them.

|-----------------------|
| id    user_id    coin |
|-----------------------|
| 1     1          1    |
| 2     2          5    |
| 3     1          3    |
| 4     2          5    |
| 5     3          2    |
| 6     4          6    |
| 7     5          10   |
| 8     5          10   |
| 9     5          25   |
| 10    1          3    |
|-----------------------|

Anyone can help me?


(system) #2

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