We're using Elasticsearch to index about 100,000 documents. Users can favorite items and currently we're using Django Haystack's RelatedSearchQuerySet
to look through the favorites table, but this executes a lot of SQL queries to filter a subset of those documents, which makes searching through a user's favorites obscenely slow.
To speed things up, I thought about adding a multivalue field to each document (e.g. favorited_by
) and storing users' primary keys in it, but since users can favorite thousands of items, popular documents will become large.
Searching through user's favorites seems like a solved problem. How is it done?