How to change the field type in an ElasticSearch Index?

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:

  "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?

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

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

Hope that helps

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

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