0

I create ElasticSearch (7.7 version) index (with mappings) in cdk script. here is my mapping for the date field:

{
  "mappings": {
    "numeric_detection": true,
    "properties": {
      "approximateArrivalTime": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss.SSSXXX"
      }, ......} 

But I keep having this error message:

  {\"type\":\"illegal_argument_exception\",\"reason\":\"failed to parse date field [2020-11-23 11:48:20.472] with format [yyyy-MM-dd HH:mm:ss.SSSXXX]\",\"caused_by\":{\"type\":\"date_time_parse_exception\",\"reason\":\"Text \\u00272020-11-23 11:48:20.472\\u0027 could not be parsed at index 23\"}}}

What could be the reason?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
A.Di
  • 53
  • 5

1 Answers1

1

The error clearly indicates that the data you are indexing in the approximateArrivalTime does not match with that of your date format specified in the index mapping.

Try indexing the document in the below format:

Index Mapping:

{
  "mappings": {
    "properties": {
      "approximateArrivalTime": {
       "type": "date",
       "format": "yyyy-MM-dd HH:mm:ss.SSS"
        }
    }
  }
}

Index Data:

{
  "approximateArrivalTime":"2020-11-23 11:48:20.472"
}
ESCoder
  • 15,431
  • 2
  • 19
  • 42
  • @A.Di did you get a chance to go through my answer, looking forward to get feedback from you :) – ESCoder Nov 23 '20 at 16:29
  • thanx for your answer, unfortunately, it didn't help. still the same error. – A.Di Nov 23 '20 at 18:10
  • @A.Di I tried it locally also, and it's working fine. Can you please share the data you are indexing for `approximateArrivalTime`? And are you getting the error when running a search query on `approximateArrivalTime` ? – ESCoder Nov 24 '20 at 01:29
  • 2020-11-23 11:48:20.472 - I try to parse this date. The error says it cannot parse this field when I provide the field type in mappings. So I guess tries index data and then fails. – A.Di Nov 24 '20 at 08:12
  • @A.Di You are indexing the same doc `2020-11-23 11:48:20.472` that you have provided in the question above. Please go through my answer, the data that you are indexing does not match with the date format you have mentioned in the index mapping. And therefore, you are getting parsing error – ESCoder Nov 24 '20 at 08:26
  • @A.Di try inserting `2020-11-23 11:48:20.472-00:00` in place of `2020-11-23 11:48:20.472` and let me know if now your issue is resolved ? – ESCoder Nov 24 '20 at 08:27
  • but i need exactly the 2020-11-23 11:48:20.472 format. which mapping format should i use in this case? – A.Di Nov 24 '20 at 12:37
  • @A.Di I have updated my answer, with new index mapping. Please go through my updated answer and let me know if this resolves your issue? – ESCoder Nov 24 '20 at 12:45
  • @A.Di If you still have any query, you can even refer to this answer https://stackoverflow.com/a/65002344/10348758, that use the same date format as you are using – ESCoder Nov 25 '20 at 10:49
  • @A.Di it's been a long time. I hope you are doing well Please don't forget to upvote and accept my answer if it helped you resolve your issue – ESCoder Dec 01 '20 at 04:17