3

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?

Blender
  • 289,723
  • 53
  • 439
  • 496

1 Answers1

0

In elasticsearch I would store the favorites together with the username for that favorite. Than add a filter to the query with the user name. You even could use the username as a multivalue field, not sure if that would scale in case of thousands of users. Advantage could be one favorite per website if multiple users create the same favorite. But I think I would keep a favorite per user.

Jettro Coenradie
  • 4,735
  • 23
  • 31