英文:
Get last document from index in Elasticsearch
问题
我正在使用github.com/olivere/elastic包进行实验;一切都正常,但我有一个问题:是否可以获取最后插入的N个文档?
From语句在搜索操作中默认起始点为0,我不确定是否可以省略它进行搜索。
英文:
I'm playing around the package github.com/olivere/elastic; all works fine, but I've a question: is it possible to get the last N inserted documents?
The From statement has 0 as default starting point for the Search action and I didn't understand if is possible to omit it in search.
答案1
得分: 0
尽管我不知道elasticsearch API中是否有一种方法可以检索最新插入的文档,但如果你存储了文档的摄取时间,可以通过以下方式实现类似的功能:
- 存储文档的摄取时间。
- 使用摄取时间进行排序。
- 检索前N个文档,即最新插入的文档。
英文:
Tldr;
Although I am not aware of a feature in elasticsearch api to retrieve the latest inserted documents.
There is a way to achieve something alike if you store the ingest time of the documents.
Then you can sort on the ingest time, and retrieve the top N documents.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论