[英]ElasticSearch failed to parse date field
I have the following query that I'm trying to run on Elasticsearch 5.6 in Kibana Dev Tools:我尝试在 Kibana Dev Tools 中的 Elasticsearch 5.6 上运行以下查询:
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"range": {
"inserted": {
"gt": "Thu Aug 20 09:01:31 +0100 2020"
}
}
}
]
}
}
}
}
}
the response I'm getting is:我得到的回应是:
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "failed to parse date field [Thu Aug 20 09:01:31 +0100 2020] with format [EEE MMM dd HH:mm:ss ZZZ yyyy]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "can_match",
"grouped": true,
The datetime format looks correct to me, what am I doing wrong?日期时间格式对我来说是正确的,我做错了什么?
In Short: 'EEE MMM dd HH:mm:ss Z yyyy' is the correct format.简而言之: 'EEE MMM dd HH:mm:ss Z yyyy' 是正确的格式。
Details:细节:
Completely customizable date formats are supported.
支持完全可定制的日期格式。 The syntax for these is explained in the Joda docs.
这些语法在 Joda 文档中进行了解释。
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss ZZZ yyyy"); DateTime dateTime = formatter.parseDateTime("Thu Aug 20 09:01:31 +0100 2020");
It is resulting in below exception:它导致以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "Thu Aug 20 09:01:31 +0100 2020" is malformed at "+0100 2020" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:866)
线程“主”java.lang.IllegalArgumentException 中的异常:格式无效:“Thu Aug 20 09:01:31 +0100 2020”在 org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.parseDateTime(DateTimeFormatter.parseDateTime) 处的“+0100 2020”格式错误.java:866)
Deduction: There is something wrong with the format defined by 'ZZZ'推论: 'ZZZ'定义的格式有问题
Z time zone offset/id zone -0800
Z时区偏移/id区-0800
Based on the investigation correct format is "EEE MMM dd HH:mm:ss Z yyyy" and not "EEE MMM dd HH:mm:ss ZZZ yyyy".根据调查,正确的格式是“EEE MMM dd HH:mm:ss Z yyyy”而不是“EEE MMM dd HH:mm:ss ZZZ yyyy”。
Considering #3 define format in your mapping like考虑 #3 在映射中定义格式,例如
{ "mappings": { "_doc":{ "properties": { "inserted":{ "type": "date", "format": "EEE MMM dd HH:mm:ss Z yyyy" } } } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.