Date Mapping Parse Failure

Hello there,

I am trying to send a date in the format 2020-10-29T05:36:06.143Z[UTC]. My mapping looks like this:

    "timeStamp": {
      "type": "date"
    }

And I am getting the following error:

Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [createdTimeStamp] of type [date] in document with id 'testId'.

Preview of field's value: 
'{offset={totalSeconds=0, rules={fixedOffset=true, transitionRules=[], transitions=[]}, id=Z}, year=2020, dayOfYear=303, nano=143000000, chronology={calendarType=iso8601, id=ISO}, minute=36, second=6, dayOfWeek=THURSDAY, month=OCTOBER, hour=5, zone={rules={fixedOffset=true, transitionRules=[], transitions=[]}, id=UTC}, dayOfMonth=29, monthValue=10}']]; 

nested: ElasticsearchException[Elasticsearch exception [type=illegal_state_exception, reason=Can't get text on a START_OBJECT at 1:72]];

I have tried:
format: "date_optional_time" - get above error
format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'[UTC]" - get type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Invalid format: [yyyy-MM-dd'T'HH:mm:ss.SSS'Z'[UTC]]: Unknown pattern letter: U]

Any other tips on how I can get this mapping to work? It's curious because I have another application that sends dates in the exact same format, transforms it to a ZonedDateTime (like I am doing), and only uses "type: date", and it works. I'm not sure what to try next, any advice is appreciated!

Welcome.

Try may be yyyy-MM-dd'T'HH:mm:ss.SSS'Z' instead?
Have a look at

It gives lot of examples and also predefined formats.

If you still can't make it work, please provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Thanks! The problem ended up being that when my ObjectMapper was stringifying my object, the date was getting parsed into a nested object.

I ended up initializing my ObjectMapper like so:

    public ObjectMapper getObjectMapper() {
        return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .registerModule(new JavaTimeModule());
    }

Thanks for the help!

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