从 ElasticSearch 索引返回最近的记录 [英] Return the most recent record from ElasticSearch index
本文介绍了从 ElasticSearch 索引返回最近的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 ElasticSearch 索引中返回最近的记录(前 1 条),类似于下面的 sql 查询;
I would like to return the most recent record (top 1) from ElasticSearch index similar to the sql query below;
SELECT TOP 1 Id, name, title
FROM MyTable
ORDER BY Date DESC;
这能做到吗?
推荐答案
你有 _timestamp 在您的文档映射中启用?
Do you have _timestamp enabled in your doc mapping?
{
"doctype": {
"_timestamp": {
"enabled": "true",
"store": "yes"
},
"properties": {
...
}
}
}
您可以在此处检查您的映射:
You can check your mapping here:
http://localhost:9200/_all/_mapping
如果是这样,我认为这可能适用于获取最新信息:
If so I think this might work to get most recent:
{
"query": {
"match_all": {}
},
"size": 1,
"sort": [
{
"_timestamp": {
"order": "desc"
}
}
]
}
这篇关于从 ElasticSearch 索引返回最近的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文