What would be the best implementation

(James Coleman) #1

I am writing a website which has a bunch of posts and allows users to favorite posts.

What I am wondering is what would be the best implementation that will allow users to search their favorites?

There will be around 4,000,000 posts and users will likely favorite about 100,000 posts, so I am not sure what would be the best implementation. I was thinking maybe have a index called favorites and have each user id with an array of post ids and then filter the posts index by the favorites index. But I am not too familiar with how to do this.

Thank you for any suggestions!

(Camilo Sierra) #2

hello @grmrgecko! i had the same user case in one project! in the first time i tried with the parent/child to be able to remove or add one favorite post independently but when the number of favorite post is too big i had problem with performances beacause at the time each favorite post represent a child.

after that i think to use as you say array (use less memory than nester or child) and the filter terms lookup, so i created a specific index for the users and as you say for each user is one document with his favorites ids, in a another index all the post and to (join) for the query use terms lookup filter this works really good and the only problem is update this favorite document with new id (but you can use update api)

(James Coleman) #3

This looks like what I am looking for, thank you for the reply!

(Imran Siddique) #4

you could also try partial updates if you expect a lot of update happening. the only requirement u wud have is u will have to store the _source

(system) #5