【发布时间】:2017-08-19 10:58:08
【问题描述】:
我绞尽脑汁想解决这个问题。一切似乎都检查过了,但它并没有像我期望的那样工作:(
我有一个索引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"
}
}
这似乎是一个精度问题,我只是不知道问题是什么,因为一切似乎都是正确的。
【问题讨论】:
标签: elasticsearch