Get last document from index in Elasticsearch

huangapple go评论93阅读模式
英文:

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中是否有一种方法可以检索最新插入的文档,但如果你存储了文档的摄取时间,可以通过以下方式实现类似的功能:

  1. 存储文档的摄取时间。
  2. 使用摄取时间进行排序。
  3. 检索前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.

huangapple
  • 本文由 发表于 2022年11月12日 01:07:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/74405930.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定