# Update type of a field in Elasticsearch

**URL:** https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964
**Category:** Elasticsearch
**Created:** [April 20, 2016, 8:49pm UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964 "2016-04-20T20:49:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ashwintumma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashwintumma/32/4828_2.png) [@ashwintumma](https://discuss.elastic.co/u/ashwintumma)
#### Post date: [April 20, 2016, 8:49pm UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964/1 "2016-04-20T20:49:53Z")

</div>

I have a index in Elasticsearch, and want to update the type of a field named currentTimeStamp from `long` to `date`, so that Kibana can work on it. Following is my current output of `_mapping` (Other fields have been removed for brevity).

```
{
  "myIndexname": {
    "mappings": {
      "myType": {
        "properties": {
          "currentTimeStamp": {
            "type": "long"
          }
         }
       }
     }
  }
}

```

When I try to run the following command for updating the type of the column to date type, I get the below mentioned error response. Any help on this is highly appreciated.

`curl -X PUT myIndexname/_mapping/myType` with the following payload

```
{
"myIndexname": {
	"properties": {
		"currentTimeStamp": {
			"type": "date",
			"format": "date_optional_time || epoch_millis"
		}
	}
 }
}

```

Error response:

```
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters: [optimizationframework : {properties={currentTimeStamp={type=date, format=date_optional_time || epoch_millis}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Root mapping definition has unsupported parameters: [optimizationframework : {properties={currentTimeStamp={type=date, format=date_optional_time || epoch_millis}}}]"
  },
  "status": 400
}
```

---

<div class="post-metadata">

### Author: ![abhijat](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@abhijat](https://discuss.elastic.co/u/abhijat)
#### Post date: [April 20, 2016, 10:54pm UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964/2 "2016-04-20T22:54:22Z")

</div>

> [@ashwintumma](#):
>
> "format": "date\_optional\_time || epoch\_millis"

Does it matter if there is space before and after ||? In their docs I do not see it. [Date field type | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html)

---

<div class="post-metadata">

### Author: ![ashwintumma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashwintumma/32/4828_2.png) [@ashwintumma](https://discuss.elastic.co/u/ashwintumma)
#### Post date: [April 21, 2016, 12:06am UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964/3 "2016-04-21T00:06:51Z")

</div>

No difference. I tried without spaces, and still does not work

---

<div class="post-metadata">

### Author: ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)
#### Post date: [April 21, 2016, 2:09am UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964/4 "2016-04-21T02:09:29Z")

</div>

You cannot change data type of a field in an existing index. Need to create a new mapping type and reindex your data. Search for reindex API in the Elastic document if you are running ES 2.3.0

---

<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: [July 5, 2017, 10:57pm UTC](https://discuss.elastic.co/t/update-type-of-a-field-in-elasticsearch/47964/5 "2017-07-05T22:57:31Z")

</div>


