Include Friend relations in user search

I'm working on creating a search feature for a social network like Mobile App.
Users can follow each other and search by username, lastname or firstname. Currently we are just indexing username, lastname and firstname into Elasticsearch and store the full user information in a seperate primary Database, referenced by an id stored in Elasticsearch and the primary DB.

Our friend relations are stored in the following schema in Google Bigtable:

requesterID:requestedID:isAccepted

The requesterID is the id of the person who requested to follow the other person. The requestedID is the id of the person who can accept the request.

So we have a bunch of rows referencing the relations between two users but we currently can't include friend relations in our user search. We would like to boost the rank of search results if the person who is searching is following the other person in the search result.
So it would list people who your following first in a search result.

Is there a way to model relations in Elasticsearch so that they can be included in a search query?

My first guess would be to store the id's of friends in an array, like: [102,106,120]. But I don't think that this is scalable if a user has thousand of friends.

To handle relation in Elasticsearch is a difficult problem and there are some limitation and trade-off between strategies.

This is only my suggestion and there could be other ways.

  1. create 2 indices
    • user index (the same as now)
    • request relation index (just as in Google Bigtable)
  2. use pivot transform function to create an index for search
    • source both indices above
    • group by user_id
    • one aggregation is top_hit bucket aggregation with filter aggregation on user index which may hit only one user document per bucket.
    • one aggregation is something like "unique values aggregation" with filter aggregation on request relation index

you can balance the performance with some transform settings.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.