# How to change the field type in an ElasticSearch Index?

**URL:** https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457
**Category:** Kibana
**Tags:** reindex
**Created:** [December 11, 2020, 11:23pm UTC](https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457 "2020-12-11T23:23:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![devbot](https://avatars.discourse-cdn.com/v4/letter/d/9de0a6/32.png) [@devbot](https://discuss.elastic.co/u/devbot)
#### Post date: [December 11, 2020, 11:23pm UTC](https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457/1 "2020-12-11T23:23:38Z")

</div>

I have index\_A, which includes a number field "foo".

I copy the mapping for index\_A, and make a dev tools call `PUT /index_B` with the field foo changed to text, so the mapping portion of that is:

```auto
  "foo": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword"
      }
    }

```

I then reindex index\_A to index\_B with:

```
POST _reindex
{
  "source": {
    "index": "index_A"
  },
  "dest": {
    "index": "index_B"
  }
}

```

When I go to view any document for index\_B, the entry for the "foo" field **is still a number**. (I was expecting for example: "foo": 30 to become "foo" : "30" in the new document's source).

As much as I've read on Mappings and reindexing, I'm still at a loss on how to accomplish this. What specifically do I need to run in order to get this new index with "foo" as a text field, and all number entries for foo in the original index changed to text entries in the new index?

---

<div class="post-metadata">

### Author: ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)
#### Post date: [December 15, 2020, 3:26pm UTC](https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457/2 "2020-12-15T15:26:23Z")

</div>

hi @devbot,

you'll probably have more luck in the Elasticearch channel with this question.

A re-index will not cast your value automatically I believe. If you want to do an explicit conversion to string, you can do this with a pipeline with the "convert-processor": [https://www.elastic.co/guide/en/elasticsearch/reference/current/convert-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/convert-processor.html)

Then use this pipeline when reindexing: [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#reindex-with-an-ingest-pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#reindex-with-an-ingest-pipeline)

Hope that helps

---

<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: [December 16, 2020, 2:34am UTC](https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457/3 "2020-12-16T02:34:18Z")

</div>

You need to use an index template to set the mapping ahead of time, or explicitly create the index with the mapping.

---

<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: [January 13, 2021, 2:34am UTC](https://discuss.elastic.co/t/how-to-change-the-field-type-in-an-elasticsearch-index/258457/4 "2021-01-13T02:34:24Z")

</div>

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