ML datafeed altering - convert text field to integer

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

"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) }}"
      }
    }
  }
 "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.

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

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