我绞尽脑汁试图解决这个问题。一切似乎都很顺利,但它并没有按照我的预期工作:(
我有一个索引test-index
并附有以下文件:
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33b_VYUyX1XZAq7NTI",
"_score": 1,
"_source": {
"timestamp": "2017-08-17T17:56:55"
}
},
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33cBN4UyX1XZAq7NTJ",
"_score": 1,
"_source": {
"timestamp": "2017-08-18T17:11:12"
}
},
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33cetJUyX1XZAq7NTK",
"_score": 1,
"_source": {
"timestamp": "2017-08-19T17:11:12"
}
}
可以看到这里我有
- 理论上最后更新的文档是在昨天。
- 今天 (08/18) 20 分钟前最后更新的文档(现在 = 撰写本文时的 17:30)
- 明天“最后更新”的文档,只是为了说明为什么我很困惑为什么这不起作用。
我有以下查询:
GET test-index/testType/_search?pretty
{
"query": {
"range": {
"timestamp": {
"lte": "now-30m"
}
}
}
}
它会提取今天(20 分钟前)更新的记录和昨天更新的记录。我原本预计它只会在昨天打破记录。
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33b_VYUyX1XZAq7NTI",
"_score": 1,
"_source": {
"timestamp": "2017-08-17T17:56:55"
}
},
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33cBN4UyX1XZAq7NTJ",
"_score": 1,
"_source": {
"timestamp": "2017-08-18T17:11:12"
}
}
]
将查询更改为gte now-30m
,它按预期工作并使用明天的时间戳提取记录。如果我将其更改为,范围查询将正常工作lte now-1d
同样,按预期仅显示 08/17 记录,但我想使用一分钟的截止时间。当我尝试工作几个小时时,也可以观察到同样的错误行为。
我尝试将格式设置为yyyy-MM-dd HH:mm:ss
并接受 ES 的默认日期映射,但没有运气。
有人知道这里可能出了什么问题吗?
编辑:它似乎也提取“今天”的记录,但也提取未来某个时间的记录,例如:
{
"_index": "test-index",
"_type": "testType",
"_id": "AV33gSs6UyX1XZAq7NTS",
"_score": 1,
"_source": {
"timestamp": "2017-08-18 19:11:12"
}
}
这似乎是一个精确问题,我只是不知道问题是什么,因为一切似乎都是正确的。