使用Elasticsearch按喜欢按帖子排序

时间:2020-11-11 14:02:27

标签: elasticsearch amazon-dynamodb

我有一个帖子和喜欢的系统。用户可以创建帖子并喜欢它们。 Rest API看起来像这样。每个帖子可以涉及多个主题:

GET /posts/{id} returns a post-object containing title, text, author name and a link to the authors rest endpoint (doesn't matter for this example)
GET /topics/{name} should return an object with both a list with the N newest posts of the topics as well as one for the N currently most popular posts
POST /posts/ creates a new post where multiple topics can be specified
POST /topics/ creates a new topic
POST /likes/ creates a like for a specified post (does not actually create an object, just adds the post-id to the given user-object's list of liked posts, which is invisible to the users, to avoid double liking)

对象存储在dynamoDB中。

我使用elasticsearch对所有帖子按主题进行分类。因此,用户发现帖子的方式是通过列出给定主题的帖子。我希望有一种方法可以按上传日期(新)和受欢迎程度对帖子进行排序。受欢迎程度是时间和喜好的混合。因此,例如,forumla可能看起来像这样:

popularity = number_of_likes - hours_since_posted 

受欢迎程度越高,该职位的排名越高。当然,按 new 进行排序很容易,只需按上传日期进行排序,但是如何按受欢迎程度进行排序? 造成这一困难的原因是,hours_since_posted会不断变化,因此喜欢的次数也会不断变化。另一个问题是喜欢与用户对象一起存储。我可以对其进行更改,以便将喜欢帖子的人员列表存储在post对象中,但是每当有人喜欢时,我就必须定期更新并重新将帖子提交给elasticsearch。

是否有一种方法可以通过Elasticsearch实施不断变化的受欢迎程度评级,或者还有另一种按受欢迎程度对帖子进行排序的方法?

0 个答案:

没有答案