# Can't change a field type

**URL:** <https://discuss.elastic.co/t/cant-change-a-field-type/267382>\
**Category:** Elasticsearch\
**Created:** [March 16, 2021, 2:03pm UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382 "2021-03-16T14:03:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![msieumouche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/msieumouche/32/85626_2.png) [@msieumouche](https://discuss.elastic.co/u/msieumouche)\
**Post date:** [March 16, 2021, 2:03pm UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382/1 "2021-03-16T14:03:01Z")

</div>

**Hello everyone,**

I have a stack with ELK and wazuh, I'm looking to change the type of some fields (" **keyword**" to " **ip**") to personal fields (srcip, dstip, etc.)

Their search fields in kibana are data.srcip, etc.

I tried this query in the dev tools:

```auto
PUT /wazuh-alerts-*/_mapping
{
  "properties": {
    "data" : {
      "properties": {
        "dstip": {
          "type": "ip"
        }
      }
    }
  }
}

```

And I get this

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "mapper [data.dstip] cannot be changed from type [keyword] to [ip]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "mapper [data.dstip] cannot be changed from type [keyword] to [ip]"
  },
  "status" : 400
}

```

Does anyone have a solution?

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 18, 2021, 5:41am UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382/2 "2021-03-18T05:41:45Z")

</div>

You can not change existing mappings in Elasticsearch so you will need to create a new index with the updated mappings, e.g. through an index template, and then reindex your data into this.

---

<div class="post-metadata">

**Author:** ![msieumouche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/msieumouche/32/85626_2.png) [@msieumouche](https://discuss.elastic.co/u/msieumouche)\
**Post date:** [March 18, 2021, 7:55am UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382/3 "2021-03-18T07:55:47Z")

</div>

thanks to you,

I have however found in: "Stack Management/Index Management/Templates/Edit Template".

A section in the web interface allowing me to change the type of my mapping.

Bye bye.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 18, 2021, 7:57am UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382/4 "2021-03-18T07:57:10Z")

</div>

That will only apply to newly created indices, not existing ones. As data ages out it will however over time resolve the issue.

---

<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:** [April 15, 2021, 7:57am UTC](https://discuss.elastic.co/t/cant-change-a-field-type/267382/5 "2021-04-15T07:57:48Z")

</div>

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