从ElasticSearch获取最后一个文档 [英] Get last document from ElasticSearch
本文介绍了从ElasticSearch获取最后一个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个弹性搜索索引,我正在向文档发送带有时间戳的附件。我想知道是否有一种方法可以根据时间戳提取最后一个文档。即说要弹性,最后一次给我文档。
so I have an elastic search index and I am sending docs to it attached with a timestamp. I am wondering if there is a way to extract the last document based on the time stamp. I.e. say to elastic give me the doc with the last time.
谢谢。
推荐答案
是的,您只需索取一个文档即可( size:1
)并按减小的时间戳进行排序
Yes, you can simply request one single document (size: 1
) and sorted by decreasing timestamp
POST index/_search
{
"size": 1,
"sort": { "timestamp": "desc"},
"query": {
"match_all": {}
}
}
这篇关于从ElasticSearch获取最后一个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文