Elastic search, sort by number of documents a user has

Viewed 26

I have an index, every document belongs to a user.

I want to be able to sort in such a way so that the results return

  • the first matching document of each user
  • the second matching document of each user
  • the third... etc

This would be to prevent one user to fill up the search results.

The only thing i could think of is to basically keep a counter in each document the user has and then sort on that counter. it would also mean that every time i delete or add a document i need to update all of the documents of the user.

Is there a better way of doing this?

1 Answers
Related