First that is not really a valid format.
the Z
means UTC
Adding the 00:00
does not add precision AND it then does not fit a format and I can not figure out how to make it fit using all the tricks / formats I have tried; basically it is a bad format
These are valid formats
2023-02-22T00:00:00Z
2023-02-22T00:00:00+00:00
So if you can fix that (in logstash I think a simple gsub
to replace the Z
with a +
will work then you just set your mapping to the following
PUT discuss-test-time
{
"mappings": {
"properties": {
"date-code": {
"type": "date",
"format": "strict_date_optional_time||yyMMdd"
}
}
}
}
# Works
POST discuss-test-time/_doc
{
"date-code" : "180502"
}
# Works
POST discuss-test-time/_doc
{
"date-code" : "2023-02-22T00:00:00+00:00"
}
# Works
POST discuss-test-time/_doc
{
"date-code" : "2023-02-22T00:00:00Z"
}
# Does Not Work
POST discuss-test-time/_doc
{
"date-code" : "2023-02-22T00:00:00Z00:00"
}
# POST discuss-test-time/_doc 201 Created
{
"_index": "discuss-test-time",
"_id": "oIF3hIwBZMvS5ljkOQn1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
# POST discuss-test-time/_doc 201 Created
{
"_index": "discuss-test-time",
"_id": "oYF3hIwBZMvS5ljkOgkD",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
# POST discuss-test-time/_doc 201 Created
{
"_index": "discuss-test-time",
"_id": "ooF3hIwBZMvS5ljkOgkN",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1
}
# POST discuss-test-time/_doc 400 Bad Request
{
"error": {
"root_cause": [
{
"type": "document_parsing_exception",
"reason": "[2:17] failed to parse field [date-code] of type [date] in document with id 'o4F3hIwBZMvS5ljkOgkb'. Preview of field's value: '2023-02-22T00:00:00Z00:00'"
}
],
"type": "document_parsing_exception",
"reason": "[2:17] failed to parse field [date-code] of type [date] in document with id 'o4F3hIwBZMvS5ljkOgkb'. Preview of field's value: '2023-02-22T00:00:00Z00:00'",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "failed to parse date field [2023-02-22T00:00:00Z00:00] with format [strict_date_optional_time||yyMMdd]",
"caused_by": {
"type": "date_time_parse_exception",
"reason": "Failed to parse with all enclosed parsers"
}
}
},
"status": 400
}