Get last document from ElasticSearch

这一生的挚爱 提交于 2019-12-09 03:38:22

问题


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.

Thanks.


回答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": {}
   }
}


来源:https://stackoverflow.com/questions/38062504/get-last-document-from-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!