# Update format for an existing field of date type

**URL:** https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787
**Category:** Elasticsearch
**Created:** [September 3, 2019, 8:35am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787 "2019-09-03T08:35:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Miao](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Miao](https://discuss.elastic.co/u/Miao)
#### Post date: [September 3, 2019, 8:35am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787/1 "2019-09-03T08:35:38Z")

</div>

I currently use ElasticSearch 7.2.0.

I followed the instructions [here](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/mapping-date-format.html) to update the format of an existing field of date type:

```auto
{
  "mappings": {
    "properties": {
      "TimeStamp": {
        "type": "date",
        "format": "yyyy-MM-ddTHH:mm:ssZ"
      }
    }
  }
}

```

However, I received this error:

```auto
{
    "error": {
        "root_cause": [
            {
                "type": "resource_already_exists_exception",
                "reason": "index [gaze/Po9kUGesSWCzfEME1sZ3Sg] already exists",
                "index_uuid": "Po9kUGesSWCzfEME1sZ3Sg",
                "index": "gaze"
            }
        ],
        "type": "resource_already_exists_exception",
        "reason": "index [gaze/Po9kUGesSWCzfEME1sZ3Sg] already exists",
        "index_uuid": "Po9kUGesSWCzfEME1sZ3Sg",
        "index": "gaze"
    },
    "status": 400
}

```

Short of creating a new index with the desired mapping and then transferring all the data from the old index to the new one, how can I update the date format of an existing field?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 3, 2019, 8:50am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787/2 "2019-09-03T08:50:02Z")

</div>

You can not update an existing field.  
You can create a new field with the settings you want to use though.

If you need to update an existing field, you need to create a new index with the mapping you want to have and reindex all your data. The reindex API might help.

---

<div class="post-metadata">

### Author: ![Miao](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@Miao](https://discuss.elastic.co/u/Miao)
#### Post date: [September 3, 2019, 9:16am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787/3 "2019-09-03T09:16:56Z")

</div>

Thanks for your reply. I tried re-indexing, but received many errors with similar messages:

```auto
{
	"index": "gaze_new",
	"type": "_doc",
	"id": "fVj-8WwBPESVc1yT9rFL",
	"cause": {
		"type": "mapper_parsing_exception",
		"reason": "failed to parse field [Timestamp] of type [date] in document with id 'fVj-8WwBPESVc1yT9rFL'",
		"caused_by": {
			"type": "illegal_argument_exception",
			"reason": "failed to parse date field [2019-09-02T14:18:35.1714475 02:00] with format [yyyy-MM-dd'T'HH:mm:ssZ]",
			"caused_by": {
				"type": "date_time_parse_exception",
				"reason": "Text '2019-09-02T14:18:35.1714475 02:00' could not be parsed at index 19"
			}
		}
	},
	"status": 400
}

```

Is this even possible to fix?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 3, 2019, 10:31am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787/4 "2019-09-03T10:31:53Z")

</div>

You defined `yyyy-MM-dd'T'HH:mm:ssZ` as the format but you sent `2019-09-02T14:18:35.1714475 02:00` which has `.1714475` in addition.

I'm not expert in time format, but you need to find the right one [from this page](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) I guess. I'm not sure if we can parse nanoseconds with the standard date field type. You probably need to use [https://www.elastic.co/guide/en/elasticsearch/reference/current/date\_nanos.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/date_nanos.html) in that case.

---

<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: [October 1, 2019, 10:31am UTC](https://discuss.elastic.co/t/update-format-for-an-existing-field-of-date-type/197787/5 "2019-10-01T10:31:53Z")

</div>

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