# ML datafeed altering - convert text field to integer

**URL:** <https://discuss.elastic.co/t/ml-datafeed-altering-convert-text-field-to-integer/293713>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning, runtime-fields\
**Created:** [January 7, 2022, 8:03am UTC](https://discuss.elastic.co/t/ml-datafeed-altering-convert-text-field-to-integer/293713 "2022-01-07T08:03:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerojin63](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zerojin63](https://discuss.elastic.co/u/zerojin63)\
**Post date:** [January 7, 2022, 8:03am UTC](https://discuss.elastic.co/t/ml-datafeed-altering-convert-text-field-to-integer/293713/1 "2022-01-07T08:03:56Z")

</div>

Hi, I want to convert keyword format field to integer in runtime mapping.  
I've tried these code but none of them worked.

```auto
"runtime_mappings": {
    "my_field.keyword": {
      "type": "keyword",
      "script": {
        "source": "if (doc.containsKey('my_field.keyword') ) { if (doc['my_field.keyword'].value != null) {return Integer.parseInt(doc['my_field.keyword'].value) }}"
      }
    }
  }

```

```auto
 "runtime_mappings": {
    "my_field.keyword": {
      "type": "keyword",
      "script": {
        "source": "String s= doc['my_field.keyword'].value; int mf= Integer.parseInt(s); return mf;"
      }
    }
  }

```

When you execute these code, following error occurs.

```auto
 "statusCode": 400,
    "error": "Bad Request",
    "message": "[search_phase_execution_exception: [class_cast_exception] Reason: class_cast_exception: Cannot cast from [int] to [void].; [class_cast_exception] Reason: class_cast_exception: Cannot cast from [int] to [void].;

```

Any help would be appreciated.

---

<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:** [February 4, 2022, 8:04am UTC](https://discuss.elastic.co/t/ml-datafeed-altering-convert-text-field-to-integer/293713/2 "2022-02-04T08:04:10Z")

</div>

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