Elasticsearch最近访问的文档
在我的应用程序中,我需要最近访问的文档首先出现在搜索中。
假设我在应用程序上也打开一个文件,该文件也在elasticsearch上索引,因此,如果我现在进行搜索,则该文件应首先出现在搜索结果中,因为该文件最近已被访问。
我该如何实现?我知道我需要在文档本身上更新一些内容,但是什么?是否已经有此用例的字段,还是我需要创建一个新的字段?如果是这样,我可以让Elasticsearch赋予这一权重吗?
谢谢
In my application I have the requirement for recently accessed documents to appear first in the search.
Let's say I open a file on my application that is indexed on Elasticsearch as well so if I now make a search this file should appear first in the search results since it was recently accessed.
How can I achieve this? I know that I need to update something on the document itself but what? Is there already a field for this use case or I need to create a new one? And if so I can I make Elasticsearch give more weight to this one?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在映射中添加一个日期:
当然,每次访问文档时,您都必须对其进行更新。显然,如果您同时连接了许多更新 /用户,则可能会遇到一些麻烦。不要忘记检查您的“刷新”设置是否可以,您也可以考虑在任何更新后也强制刷新。
要检索文档,只需按以下日期字段(DESC)进行排序。
如果您的用户在每次访问它时修改文档,则可以考虑使用Collape( https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html )
注意:
如果仅需要保留X个最后访问的文档(让S的最后5个),最好的解决方案是将ES文档保存在应用程序端的静态列表中。
Add a date in your mappings:
Of course, you would have to update it each time a document is accessed. Obviously if you have many update / user connected at the same time you could have some trouble. Dont forget to check if your "refresh" settings is ok, you could consider to force refresh after any update too.
To retrieve documents, just sort by this date field (desc).
If your users modify documents each time they accessed it, you could consider use collape (https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html)
Note:
If you need only keep the X last accessed documents (let s say the last 5), the best solution is to keep es document in a static list on application side.