Invalid Date Format

This is my index mapping:

 "properties": {
                "hour": {
                    "type": "date"
                },
                "timestamp": {
                    "type": "date"
                }
            }

I am trying to add different entries having different timestamps. I am using Java and storing LocalDateTime from my app. It works fine for a lot of entries, but for some entries, it fails with the error:

ERROR ElasticsearchException[Elasticsearch exception [type=exception, reason=java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: unable to parse date [2020-02-18T13:42:54Z]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=java.lang.IllegalArgumentException: unable to parse date [2020-02-18T13:42:54Z]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=unable to parse date [2020-02-18T13:42:54Z]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Invalid format: "2020-02-18T13:42:54Z" is malformed at "Z"]];

I understand that ES also wants milliseconds, but in this case, the time doesn't have millis so they can automatically be truncated, but the object is still a valid LocalDateTime object so ES should accept it. I thought the problem could be in the fact that ES is pretty strict and won't accept anything unless I append 000 with the date. However, the funny thing is that when I manually run a query on ES, it accepted the entry without any problem

{
"took": 296,
"timed_out": false,
"_shards": {
    "total": 400,
    "successful": 400,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 1,
    "max_score": null,
    "hits": [
        {
            "_source": {
                "hour": "2020-02-19T15:00Z",
                "timestamp": "2020-02-18T13:42:54Z"
            }
        }
    ]
 }
}

What exactly am I missing here?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.