# How to change the mappings of an index in python itself?

**URL:** <https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666>\
**Category:** Elasticsearch\
**Created:** [December 7, 2022, 9:55am UTC](https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666 "2022-12-07T09:55:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashank02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shashank02/32/99866_2.png) [@Shashank02](https://discuss.elastic.co/u/Shashank02)\
**Post date:** [December 7, 2022, 9:55am UTC](https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666/1 "2022-12-07T09:55:44Z")

</div>

I want to change the type of text to keyword of a csv file that I'm uploading in Elasticsearch using the Elastic Search client in Python. But I'm getting this error:  
elasticsearch.BadRequestError: BadRequestError(400, 'illegal\_argument\_exception', 'mapper [source] cannot be changed from type [text] to [keyword]').  
Can anyone help me with this?

---

<div class="post-metadata">

**Author:** ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)\
**Post date:** [December 7, 2022, 10:12am UTC](https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666/2 "2022-12-07T10:12:26Z")

</div>

It is not possible to update the mapping of an existing field. If the mapping is set to the wrong type, re-creating the index with updated mapping and re-[indexing](https://opster.com/guides/elasticsearch/glossary/elasticsearch-indexing) is the only option available.

Except for supported [mapping parameters] you can’t change the mapping or field type of an existing field. Changing an existing field could invalidate data that’s already indexed.

I'm not sure on how you mapping is.

You can try this option. Modify your mapping to add an `keyword` sub-field to your existing field and try.

```auto
PUT index/_mapping
{
  "properties": {
    "your_text_field": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}

```

---

<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:** [December 7, 2022, 10:15am UTC](https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666/3 "2022-12-07T10:15:23Z")

</div>

Even in that case, if you modify the mapping, you will have to reindex the existing documents...

Unless you define a `runtime` field. See [Runtime fields | Elasticsearch Guide [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html)

---

<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 4, 2023, 10:16am UTC](https://discuss.elastic.co/t/how-to-change-the-mappings-of-an-index-in-python-itself/320666/4 "2023-01-04T10:16:23Z")

</div>

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