# Best way to reindex text to keyword

**URL:** <https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119>\
**Category:** Elasticsearch\
**Created:** [September 10, 2022, 4:51pm UTC](https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119 "2022-09-10T16:51:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_s/32/98686_2.png) [@Mark\_S](https://discuss.elastic.co/u/Mark_S)\
**Post date:** [September 10, 2022, 4:51pm UTC](https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119/1 "2022-09-10T16:51:01Z")

</div>

I want to re-index a text field to keyword.  
I have multiple indices (myindex-000001, myindex-000002, etc)

In order to reindex I must: a) get the mapping b) create a new index mynewindex-000001 same field name but different type (text-\>keyword).

Then repeat the procedure for all indices.  
Is this logic correct?

Here is the index mapping ( I want to change host,path and tags to type "keyword")

```auto
{
  "myindex-000001" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "@version" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "host" : {
          "type" : "text"
        },
        "message" : {
          "type" : "text"
        },
        "path" : {
          "type" : "text"
        },
        "tags" : {
          "type" : "text"
        },
        "timestamp" : {
          "type" : "date"
        },
        "version" : {
          "type" : "text"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [September 11, 2022, 10:43am UTC](https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119/2 "2022-09-11T10:43:56Z")

</div>

Hi @Mark_S  
I would do it that way. I would create the new index with the keyword type in the correct fields and use the [Api reindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html). I don't know if you use Alias ​​but I would also start applying it to the indexes to facilitate migration.

---

<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:** [September 12, 2022, 6:35am UTC](https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119/3 "2022-09-12T06:35:20Z")

</div>

You should be able to do this with the reindex API as it uses `_source`, which you haven't disabled. Then define the new mapping as per your requirements.

---

<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 10, 2022, 6:36am UTC](https://discuss.elastic.co/t/best-way-to-reindex-text-to-keyword/314119/4 "2022-10-10T06:36:06Z")

</div>

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