Timestamp field in a document throws an error when updating the time but passes on create

I have a spring boot application which talks to elastic search db.

My entity looks similar to this:

@Data 
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Document(indexName = "preferences", type = "preference")
public class preference implements Serializable {
        @Field(type = FieldType.Date, store = true, format = DateFormat.custom, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
        private OffsetDateTime updatedAt;
    }

When I do a get on the index on kibana I can see the property being set:

"updatedAt" : {
      "type" : "date",
      "store" : true,
      "format" : "yyyy-MM-dd'T'HH:mm:ss.SSSZZ"
    }

I set this field before storing in elasticsearch by running:
OffsetDateTime.now(ZoneId.of(ZoneOffset.UTC.getId()))

Now, when I create an entry in the index, everything looks good. It passes without any exceptions. But when I try to update an existing entry I get a 400 bad request and the error says:

"message": "Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [updatedAt] of type [date] in document with id '-N63_20BpFfl1cRNjDbX'. Preview of field's value: '{dateTime={date={month=10.0, year=2019.0, day=24.0}, time={hour=21.0, nano=9.05735E8, minute=41.0, second=54.0}}, offset={totalSeconds=0.0}}']"

I'm using elastic search 7.3.2 version. I'm not sure what I'm doing wrong here, but if the field is being populated on creating a new document then it should be fine while updating it?!?!?

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