Scripted fields sort

Hello,
I've faced the following issue:

I've created a script field which returns String type

But when I try to make sorting on this field by the Kibana means there's an error

"Error loading data
[script_exception] compile error"

I saw the reuqest, which was leaded to elastic:

{
  "version": true,
  "size": 500,
  "sort": [
    {
      "event_date": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    },
    {
      "_script": {
        "script": {
          "source": "if (doc.containsKey('message.keyword')) {\n//if (doc['message.keyword'].size() == 0) return 'field not found';\ndef path = doc['message.keyword'].value;\nString[] message = /\\n/.split(path);\nString param = 'IP = ';\n for (int i = 0; i < message.length; i++) {\n        int index = message[i].indexOf(param);\n        if (index > -1) {\n            return message[i].substring(index+param.length());\n           // return 'ее';\n        }\n    }\nreturn '';\n} else return '';",
          "lang": "painless"
        },
        "type": "number",
        "order": "asc"
      }
    }
  ],
.........
 }

And I've found out that Kibana gives this filed "type": "number"
If i send the request directly to elastic, by changing "type": "number", to "type": "string" Then the request is running.

Could you please, expain, what's the problem?

Hi and welcome to our community!

This seems to be a bug, have a look here:

Best,
Matthias