# \[Solved\] Cast/Map IP Field to IP Type

**URL:** <https://discuss.elastic.co/t/solved-cast-map-ip-field-to-ip-type/312558>\
**Category:** Elasticsearch\
**Created:** [August 21, 2022, 9:44pm UTC](https://discuss.elastic.co/t/solved-cast-map-ip-field-to-ip-type/312558 "2022-08-21T21:44:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snkhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/snkhan/32/109912_2.png) [@snkhan](https://discuss.elastic.co/u/snkhan)\
**Post date:** [August 21, 2022, 9:44pm UTC](https://discuss.elastic.co/t/solved-cast-map-ip-field-to-ip-type/312558/1 "2022-08-21T21:44:49Z")

</div>

Hello,

I am a new ELK user, and am trying in vain to cast an existing field containing an IP address to an IP data type. From the copious searches it is clear that I must use mappings, but my attempts to do so have failed.

This is what I have tried so far, using the Dev console:

```auto
PUT /myindex/_mapping
{
  "properties": {
    "collected_host": {
      "type": "ip",
      "ignore_malformed": true
    }
  }
}

```

I have also tried:

```auto
PUT myindex
{
  "mappings": {
    "properties": {
      "collected_host": {
        "type": "ip",
        "ignore_malformed": true
      }
    }
  }
}

```

The error retuned is:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "resource_already_exists_exception",
        "reason" : "index [myindex/wI-2en84RyaNRct_2yzS5Q] already exists",
        "index_uuid" : "wI-2en84RyaNRct_2yzS5Q",
        "index" : "myindex"
      }
    ],
    "type" : "resource_already_exists_exception",
    "reason" : "index [myindex/wI-2en84RyaNRct_2yzS5Q] already exists",
    "index_uuid" : "wI-2en84RyaNRct_2yzS5Q",
    "index" : "myindex"
  },
  "status" : 400
}

```

I do not mind deleting my index and starting afresh. My preference would be to have this configured in my existing `myindex.conf` file, but I am happy to try any suggestion to get this working.

Thank you, and have a great day.

---

<div class="post-metadata">

**Author:** ![snkhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/snkhan/32/109912_2.png) [@snkhan](https://discuss.elastic.co/u/snkhan)\
**Post date:** [August 21, 2022, 9:59pm UTC](https://discuss.elastic.co/t/solved-cast-map-ip-field-to-ip-type/312558/2 "2022-08-21T21:59:15Z")

</div>

Solved. I deleted my index, re-created it, and then, before importing my documents again, ran the following using the Dev Console:

```auto
PUT /myindex/_mapping
{
  "properties": {
    "collected_host": {
      "type": "ip",
      "ignore_malformed": true
    }
  }
}

```

---

<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:** [September 18, 2022, 9:59pm UTC](https://discuss.elastic.co/t/solved-cast-map-ip-field-to-ip-type/312558/3 "2022-09-18T21:59:59Z")

</div>

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