0
我一直在从自动生成的时间戳移动到映射的时间戳,并且查询不再工作。当使用自动生成的时间戳,我是能够执行这种查询:在映射的时间戳上过滤
FilterBuilder filter = FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
而且通过最新表述,如“现在-1H”会的工作。现在,我已经介绍了以下映射:
"collections": {
"_timestamp": {
"enabled": true,
"path": "my_date",
"ignore_missing": false
},
"properties": {
"author": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"analyzer": "lowercase"
},
"my_date": {
"type": "date"
}
}
}
我存储my_date为Unix纪元格式,我不能再查询:
FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
返回空的结果,而查询
FilterBuilders.rangeFilter("my_date").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
与异常
from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"my_date":{"from":"2015-09-04T19:52:15.001+01:00","to":"2015-09-04T21:52:15.001+01:00","include_lower":true,"include_upper":true}}}}}}]]]; nested: NumberFormatException[For input string: "2015-09-04T19:52:15.001+01:00"];
失败
它看起来像我可以做的唯一的查询是通过在my_date上使用时间戳的数字值。有什么更好的,我可以希望?
我刚刚错误地复制了一部分映射,my_date在属性节点内正确。我已经更新了这个问题,还注意到如果我使用数字时间戳查询my_date属性,它可以正常工作 – Edmondo1984
更新了答案。 – imotov
您正在使用哪个版本的ES?您正在运行的查询是为我返回的ParseException – Edmondo1984