Elasticsearch 查询以获取一个多小时前修改的项目
Elasticsearch query to get items that were modified more then an hour ago
我在 elasticsearch 中有以下索引项。
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640085989000}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
}
如何根据 lastUpdated
值获取一个多小时前更新的项目?我一直在尝试在互联网上找到的一些解决方案,但大多数都是用于查询字符串而不是数字字段。
感觉 range
查询就可以完成工作 [doc]
您要查找的部分是range on dates
您的查询应该大致如下所示:
GET /<your index>/_search
{
"query": {
"range": {
"lastUpdated": {
"gte": "now-1h"
}
}
}
}
确保您的映射是正确的,并且 lastUpdated
具有正确的格式 [doc]。
ES 为您提供 now
和 h
等关键字,简单 date math queries. Along with a range query 您应该可以做到:
{
"query": {
"range": {
"lastUpdated": {
"lt": "now-1h"
}
}
}
}
我在 elasticsearch 中有以下索引项。
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640085989000}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
}
如何根据 lastUpdated
值获取一个多小时前更新的项目?我一直在尝试在互联网上找到的一些解决方案,但大多数都是用于查询字符串而不是数字字段。
感觉 range
查询就可以完成工作 [doc]
您要查找的部分是range on dates
您的查询应该大致如下所示:
GET /<your index>/_search
{
"query": {
"range": {
"lastUpdated": {
"gte": "now-1h"
}
}
}
}
确保您的映射是正确的,并且 lastUpdated
具有正确的格式 [doc]。
ES 为您提供 now
和 h
等关键字,简单 date math queries. Along with a range query 您应该可以做到:
{
"query": {
"range": {
"lastUpdated": {
"lt": "now-1h"
}
}
}
}