# Dealing with changes in field datatype

**URL:** <https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952>\
**Category:** Elasticsearch\
**Created:** [October 18, 2021, 5:56am UTC](https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952 "2021-10-18T05:56:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raonic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raonic/32/81695_2.png) [@raonic](https://discuss.elastic.co/u/raonic)\
**Post date:** [October 18, 2021, 5:56am UTC](https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952/1 "2021-10-18T05:56:13Z")

</div>

Hello,

I have an Elasticsearch index where fields are configured by clients (indirectly) i.e., the clients configure the datatype for these fields through an interface and then I have a workflow which creates the actual mapping for these fields in the index. The clients then index data and perform queries.

If a client wishes to change the field datatype for a given field, I would have to re-index all documents to a new index to change the datatype for the field. This is fine if performed infrequently, however if some client changes the datatype too many times, too many reindexing operations are not desirable, given the fact that the index contains a lot of documents from other clients as well (greater than 30 million and growing) and I feel this would affect the cluster negatively.

Is there a way where I can solve this without having to re-index frequently? Would field aliases work here? Eg: I create a field alias for a field that client wishes to create. Every time client changes the datatype, I would just create a new field and point the field alias to the new field.  
Any other workarounds/suggestions are also welcome.

Thanks,  
Raonic

---

<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:** [October 18, 2021, 5:58am UTC](https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952/2 "2021-10-18T05:58:37Z")

</div>

> [@raonic](#):
>
> Would field aliases work here?

Yeah that seems to be the best approach, given your other limitations.

---

<div class="post-metadata">

**Author:** ![raonic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raonic/32/81695_2.png) [@raonic](https://discuss.elastic.co/u/raonic)\
**Post date:** [October 18, 2021, 6:41pm UTC](https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952/3 "2021-10-18T18:41:08Z")

</div>

However, I just realized field aliases cannot be used in index or update operations. So I wonder how writes can be performed.  
Example:

1. User creates field `postalCode` of type `text`. The workflow creates the alias `postalCode` and points it to a field called `postalCode-0001` of type `text`.
2. Now, user changes the type of the field to type `long`. The workflow simply creates a new field `postalCode-0002` of type `long` and changes the alias to point to this new field.
3. How do I manage write operations here? Since I cannot use the `postalCode` alias field to perform the writes.

Thanks,  
Raonic

---

<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 15, 2021, 6:41pm UTC](https://discuss.elastic.co/t/dealing-with-changes-in-field-datatype/286952/4 "2021-11-15T18:41:22Z")

</div>

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