elasticsearch failed to parse date
Asked Answered
S

2

6

I've the following index definition for the date:

"handshaketime" : {"type":"date","format":"YYYY-MM-ddTHH:mm:ss.SSSZ"}

And the actual date is of this form:

"handshaketime":"2015-04-07T10:43:03.000-07:00"

I've specified that date coming from DB has the above mentioned format but elasticsearch still gives me the following error.

Caused by: org.elasticsearch.index.mapper.MapperParsingException: failed to
parse date field [2015-04-07T10:43:03.000-07:00], tried both date format
[YYYY-MM-dd HH:mm:ss], and timestamp number with locale []

I'm using elasticsearch 1.4.4 with jdbc_river 1.4.0.10.

Please tell me whats going on.

Sargeant answered 18/3, 2015 at 12:28 Comment(0)
S
7

In trying to fix this error, I came across the same result, despite what @Vineeth provided. I pointed to him that for some reason ES is not showing the format that we supplied but instead gives the same error over and over again.

Finally, I came across a post describing the removal of all indexes in ES and re-submitting our index/mapping document afresh (aka clean-slating). Voila! it worked, in fact it worked if i just gave the following:

"handshaketime":{"type":"date", "format": "dateOptionalTime"}

Not even custom format that me and @Vineeth were discussing about!!

So if you are struggling with this problem, make sure there are NO indexes in the ES that may be preventing you to index your new document.

Thanks for trying to sort this issue @Vineeth.

Sargeant answered 18/3, 2015 at 17:49 Comment(1)
Worked for me. But still, need to drop and recreate index because I get an error if try to update the mapping.Terena
E
2

You have to give it as follows - There should be single quotes for T as its not a time identifier.

 {"type":"date","format":"YYYY-MM-dd'T'HH:mm:ss.SSSZ"}

If you are using shell script , you need to give it as follows -

 {"type":"date","format":"YYYY-MM-dd'"'T'"'HH:mm:ss.SSSZ"}
Exurbia answered 18/3, 2015 at 13:35 Comment(5)
Thank you Vineeth, it still complains: Caused by: java.lang.IllegalArgumentException: Invalid format: "2015-03-31T16:25:56.000-07:00" is malformed at "T16:25:56.000-07:00"Sargeant
i gave curl -XPUT command to put the index doc in ES and gave this: "handshaketime":{"type":"date","format":"YYYY-MM-dd'"'T'"'HH:mm:ss.SSSZ"}, But i still get the same error? It seems like ES is ignoring the format altogether because it should atleast complain about our format being wrong...right?Sargeant
and the index output (in the browser) shows the following: "handshaketime":{"type":"date","format":"YYYY-MM-dd'T'HH:mm:ss.SSSZ"}, So it reads the format but does not seem to apply it to our time.Sargeant
Can you try this format YYYY-MM-dd'T'HH:mm:ss.SSSZZExurbia
I use this "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" and it is fine.Nirvana

© 2022 - 2024 — McMap. All rights reserved.