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

**URL:** https://discuss.elastic.co/t/timestamp-field-in-a-document-throws-an-error-when-updating-the-time-but-passes-on-create/205160
**Category:** Elasticsearch
**Created:** [October 24, 2019, 10:01pm UTC](https://discuss.elastic.co/t/timestamp-field-in-a-document-throws-an-error-when-updating-the-time-but-passes-on-create/205160 "2019-10-24T22:01:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![afzal](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@afzal](https://discuss.elastic.co/u/afzal)
#### Post date: [October 24, 2019, 10:01pm UTC](https://discuss.elastic.co/t/timestamp-field-in-a-document-throws-an-error-when-updating-the-time-but-passes-on-create/205160/1 "2019-10-24T22:01:23Z")

</div>

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

My entity looks similar to this:

```auto
@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:

```auto
"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?!?!?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 21, 2019, 10:01pm UTC](https://discuss.elastic.co/t/timestamp-field-in-a-document-throws-an-error-when-updating-the-time-but-passes-on-create/205160/2 "2019-11-21T22:01:23Z")

</div>

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