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.

BoCode
  • 847
  • 4
  • 17
  • 33

2 Answers2

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.

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
BoCode
  • 847
  • 4
  • 17
  • 33
  • Worked for me. But still, need to drop and recreate index because I get an error if try to update the mapping. – Vlad Feb 19 '18 at 06:26
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"}
Vineeth Mohan
  • 18,633
  • 8
  • 63
  • 77
  • 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" – BoCode Mar 18 '15 at 14:15
  • 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? – BoCode Mar 18 '15 at 14:55
  • 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. – BoCode Mar 18 '15 at 14:57
  • Can you try this format YYYY-MM-dd'T'HH:mm:ss.SSSZZ – Vineeth Mohan Mar 18 '15 at 15:12
  • I use this "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" and it is fine. – ligand Feb 17 '22 at 08:36