# Changing data type

**URL:** https://discuss.elastic.co/t/changing-data-type/87852
**Category:** Elasticsearch
**Created:** [June 1, 2017, 7:31am UTC](https://discuss.elastic.co/t/changing-data-type/87852 "2017-06-01T07:31:28Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 1, 2017, 7:31am UTC](https://discuss.elastic.co/t/changing-data-type/87852/1 "2017-06-01T07:31:28Z")

</div>

Is there any workaround to change the datatype of a field without reindexing?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 1, 2017, 7:31am UTC](https://discuss.elastic.co/t/changing-data-type/87852/2 "2017-06-01T07:31:58Z")

</div>

Nope.

---

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 1, 2017, 7:32am UTC](https://discuss.elastic.co/t/changing-data-type/87852/3 "2017-06-01T07:32:55Z")

</div>

for deleting a mapping and its documents?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 1, 2017, 7:33am UTC](https://discuss.elastic.co/t/changing-data-type/87852/4 "2017-06-01T07:33:14Z")

</div>

Sorry?

---

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 1, 2017, 7:35am UTC](https://discuss.elastic.co/t/changing-data-type/87852/5 "2017-06-01T07:35:34Z")

</div>

i want to change the datatype of a field  
Since i can't do that without reindexing, i thought that i could just drop the mapping and create a new one with the changes i need and then push the documents to the new mapping  
is that possible?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 1, 2017, 7:36am UTC](https://discuss.elastic.co/t/changing-data-type/87852/6 "2017-06-01T07:36:40Z")

</div>

Not unless you delete all the data as well.

---

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 1, 2017, 7:44am UTC](https://discuss.elastic.co/t/changing-data-type/87852/7 "2017-06-01T07:44:16Z")

</div>

Is there any reason why changing the field datatype isn't supported?  
My index will contain a large volume of data which needs to be available at all times.  
reindexing is an expensive operation and i just want to avoid or bypass it

---

<div class="post-metadata">

### Author: ![Heinmci](https://avatars.discourse-cdn.com/v4/letter/h/6a8cbe/32.png) [@Heinmci](https://discuss.elastic.co/u/Heinmci)
#### Post date: [June 1, 2017, 7:48am UTC](https://discuss.elastic.co/t/changing-data-type/87852/8 "2017-06-01T07:48:57Z")

</div>

This might not be usable at all since it seems like pretty bad practice but it might be of use to you :  
Create a new field with the new dataType you want with the put mapping api :

```auto
PUT index/_mapping/type
{
  "properties": {
    "newField": {
      "type": "keyword"
    }
  }
}

```

And then run an update by query on the documents you want to have their field change :

```auto
POST index/type/_update_by_query
{
  "script": {
    "inline": "ctx._source.newField= ctx._source.oldFieldWithOtherDataType",
    "lang": "painless"
  },
  "query": {
    "match_all": {
    }
  }
}

```

---

<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: [June 1, 2017, 7:51am UTC](https://discuss.elastic.co/t/changing-data-type/87852/9 "2017-06-01T07:51:41Z")

</div>

> [@chanakyan-arivumani](#):
>
> Is there any reason why changing the field datatype isn't supported?

Yes. One of them is that elasticsearch/Lucene is using immutable files. What has been indexed will remain as it was when you indexed it which will lead to inconsistencies.  
The only way to "regenerate" a new version of the Lucene files is to reindex.

---

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 2, 2017, 6:34am UTC](https://discuss.elastic.co/t/changing-data-type/87852/10 "2017-06-02T06:34:42Z")

</div>

Thanks Heinmci  
but this doesn't solve my issue..

---

<div class="post-metadata">

### Author: ![chanakyan-arivumani](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@chanakyan-arivumani](https://discuss.elastic.co/u/chanakyan-arivumani)
#### Post date: [June 2, 2017, 6:42am UTC](https://discuss.elastic.co/t/changing-data-type/87852/11 "2017-06-02T06:42:53Z")

</div>

thanks guys for responding promptly  
you've been of great help to me

---

<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: [June 30, 2017, 6:43am UTC](https://discuss.elastic.co/t/changing-data-type/87852/12 "2017-06-30T06:43:06Z")

</div>

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