Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch date format

I'm trying to send the following JSON input to elasticsearch but I'm obtaining a parser error.

This the JSON input

{
    "chassisNumber": "654321",
    "position": "40.480143, -3.688960",
    "issue": "Position",
    "timestamp": "2016-07-15T15:29:50+02:00[Europe/Paris]"
}

the Index definition

{
   "mappings":{
      "vehicle":{
         "properties":{
            "vehicle":{
               "type":"string"
            },
            "position":{
               "type": "geo_point"
            },
            "issue":{
               "type":"string"
            },
            "timestamp":{
               "type":"date",
               "format":"YYYY-MM-DD'T'HH:mm:ssZ"
            }
         }
      }
   }
}

And the error associated with the "timestamp" field.

"reason": "Invalid format: \"2016-07-15T15:29:50+02:00[Europe/Paris]\" is malformed at \"[Europe/Paris]\""

I tried with a few date formats but no one was success. Can anybody help me to define the correct format to parse the "timestamp" field in elasticsearch?

Thanks!!!

like image 957
gleX Avatar asked Aug 05 '16 13:08

gleX


People also ask

How are dates stored in Elasticsearch?

Date field typeedit. JSON doesn't have a date data type, so dates in Elasticsearch can either be: strings containing formatted dates, e.g. "2015-01-01" or "2015/01/01 12:10:30" . a number representing milliseconds-since-the-epoch.

What is DD format for date?

dd – two-digit day of the month, e.g. 02. ddd – three-letter abbreviation for day of the week, e.g. Fri. dddd – day of the week spelled out in full, e.g. Friday.


1 Answers

As you can see in the mapping that your field timestamp is mapped as date type with format YYYY-MM-DD'T'HH:mm:ssZ. So, Elasticsearch would want the timestamp field to be passed in same format. The data you are passing is 2016-07-15T15:29:50+02:00[Europe/Paris] which includes [Europe/Paris] after zone data which is not given in mapping and does not follow default ISO 8601 format supported by Elasticsearch (more data available here).

You can read more on default date format supported by Elasticsearch here.

So either you have to remove extra data passed to Elasticsearch and keep it according to mapping

{
    "chassisNumber": "654321",
    "position": "40.480143, -3.688960",
    "issue": "Position",
    "timestamp": "2016-07-15T15:29:50+02:00"
}

or change your mapping to custom date format which follows the joda syntax defined here. In your case if it is literal zone required you have to use z too.

like image 190
Sumit Avatar answered Sep 19 '22 08:09

Sumit