Every attempt fails because the date can't be parsed (example error for the first case, all looks the same).
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [date1] of type [date] in document with id '1'. Preview of field's value: '2020-05-07 13:16:44+00:00'"
}
],
"type" : "mapper_parsing_exception",
"reason" : "failed to parse field [date1] of type [date] in document with id '1'. Preview of field's value: '2020-05-07 13:16:44+00:00'",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "failed to parse date field [2020-05-07 13:16:44+00:00] with format [yyyy-MM-dd HH:mm:ssZ]",
"caused_by" : {
"type" : "date_time_parse_exception",
"reason" : "Text '2020-05-07 13:16:44+00:00' could not be parsed at index 19"
}
}
},
"status" : 400
}
Assuming this is on some late 7.x version, according to the java the docs that we link from our format docs, five is the magic number in this case:
Offset Z : This formats the offset based on the number of pattern letters. One, two or three letters outputs the hour and minute, without a colon, such as '+0130'. The output will be '+0000' when the offset is zero. Four letters outputs the full form of localized offset, equivalent to four letters of Offset-O. The output will be the corresponding localized offset text if the offset is zero. Five letters outputs the hour, minute, with optional second if non-zero, with colon. It outputs 'Z' if the offset is zero. Six or more letters throws IllegalArgumentException .
This at least works for me on 7.6.2
DELETE test
PUT /_template/test
{
"index_patterns": ["test"],
"mappings": {
"properties": {
"date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ssZZZZZ" }
}
}
}
PUT /test/_doc/1
{ "date1": "2020-05-07 13:16:44+00:00" }
GET /test/_search
{
"docvalue_fields": ["date"]
})
Formatting is also often weird to me, I keep re-reading those docs and need to try things every time, and zone offsets are especially hard. Hope this helps.
Great @cbuescher, that worked as expected! As you said, really confusing, since somewhere I've documentation where my exact example was supposed to work with ZZ, somewhere else with ZZZZ...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.