How can ElasticSearch be used to implement social search?

后端 未结 5 665
猫巷女王i
猫巷女王i 2021-01-30 03:15

I’m trying to create a business search with social features using ElasticSearch. I have a business directory, and users can interact with those businesses in different ways: b

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 04:13

    I'm voting for a modified #2.

    Instead of storing each user/score pair inside of the business document itself, I would create a Parent/Child relationship. This lets you update the score of the child (the user scores) without having to reindex the entire business document (and all the other user scores).

    Check out this page for a great tutorial parent/children are about halfway down: http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/

    Then you can use a has_child filter or top_children query to find only those businesses that your friends have scores for. There are a few caveats about ordering children documents, but it's covered by that tutorial so make sure you read to the bottom.

    Then I'd just perform a normal query for all "non-social" ranked searches.

    Alternatively, you could lump everything together and add boosts to the matches that your friends have scored, so that everything ranks appropriately. It may just be easier to perform two queries and combine them yourself.

提交回复
热议问题