Searching for documents only if user has it


(Jeff Oh) #1

I want to know how to achieve this scenario as efficient as possible.

In a following situation,

  • There are many documents.
  • Users can choose documents to have. (just like facebook's like feature)

I'd like to search only from documents that a certain user has chosen. Because this is N:M mapping, I stored document index and (document id - user id) in a separate index.

What is the best possible way to achieve this? I've been spending a lot of time thinking for a good solution, but didn't come up with a good one. Can anyone enlighten me?

Thanks in forward.


(Shay Banon) #2

Since there is no join functionality in elasticsearch, then storing this relationship in a different index will not help. You can either reindex the doc with an array of not_analyzed field that has the user ids on a document that represents users that liked it. This will require you to reindex the whole doc again.

Another option is to have a child document associated with the main doc that represents a like, and then use a has_child filter to filter those out. This means that a like is just an index of a new doc that is a child doc to the "main" doc. Has child is a bit expensive, but will do the work.

I plan to try and tackle this "changing fields" problem in later versions. Its a big one to tackle though... :slight_smile:
On Thursday, March 10, 2011 at 11:30 AM, Jeff Oh wrote:

I want to know how to achieve this scenario as efficient as possible.

In a following situation,

  • There are many documents.
  • Users can choose documents to have. (just like facebook's like feature)

I'd like to search only from documents that a certain user has chosen.
Because this is N:M mapping, I stored document index and (document id - user
id) in a separate index.

What is the best possible way to achieve this? I've been spending a lot of
time thinking for a good solution, but didn't come up with a good one. Can
anyone enlighten me?

Thanks in forward.

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Searching-for-documents-only-if-user-has-it-tp2659739p2659739.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #3