Painless compile error using regex pattern

Hello,

I'm getting a compile error when using regex patterns inside a scripted field. I couldn't figure out why this error is happening though, since I'm pretty sure the script is right, based on the docs.

Here is the error:

    "root_cause": [
      {
       "type": "script_exception",
       "reason": "compile error",
       "script_stack": [
    "... ate'].value;\nPattern p = /SJC/;\n\n// lp =~ p \n\nlp",
    "                             ^---- HERE"
       ],
       "script": "def lp = doc['last_breadcrumbs_sorting_record.destination.license_plate'].value;\nPattern p = /SJC/;\n\n// lp =~ p \n\nlp",
       "lang": "painless",
       "position": {
    "offset": 93,
    "start": 68,
    "end": 116
       }
      }, 

And this is an example document:

    {
      "_id": "3268105",
      "last_breadcrumbs_sorting_record": {
       "destination": {
        "license_plate": "SJC20200623088"
       }
      },

Im using kibana's scripted field editor, running on v 7.8.1

Tks

Hi Rodrigo,
That looks right to me. Please post the section of the error below "position". It'll look like this:

    "position" : {
      "offset" : 103,
      "start" : 78,
      "end" : 122
    },
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Error compiling regex: Unexpected internal error"
    }
  },

Also, if you can post the raw script directly, it'll be easier to debug without the escaped newlines.

Hi @stu thanks for the response!

I've just checked the whole error stack and saw that regexes were not enabled :confused:

"caused_by": {
     "type": "illegal_state_exception",
     "reason": "Regexes are disabled. Set [script.painless.regex.enabled] to [true] in elasticsearch.yaml to allow them. Be careful though, regexes break out of Painless's protection against deep recursion and long loops."
    }
   }

The stack was so long (and with a repeating pattern on 90% of the stack) that I didn't pay attention to the full description.

Tks

1 Like