Java regex matcher in painless seems not to be working

Hi
i try to match a simple pattern from a string, like this:

GET testindex/_search
{
  "query": {
    "match_all": {}
  }, 
  "script_fields": {
    "free_float": {
      "script": {
        "source": """
        def m = /([0-9])+/.matcher('122334');
        String result = m.group(1);
        return (result)
        """
      }
    }
  }
}

the regex should be working, i tested it in regex101.com.
But i get always this error:

        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "java.base/java.util.regex.Matcher.group(Matcher.java:644)",
            "result = m.group(1);\n        ",
            "          ^---- HERE"
          ],
          "script" : " ...",
          "lang" : "painless",
          "position" : {
            "offset" : 72,
            "start" : 62,
            "end" : 91
          },
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "No match found"
          }
        }
      }

The strange thing is, that when i run

GET testindex/_search
{
  "query": {
    "match_all": {}
  }, 
  "script_fields": {
    "free_float": {
      "script": {
        "source": """
        def m = /([0-9])+/.matcher('122334');
        def result = m.matches();
        return (result)
        """
      }
    }
  }
}

i get as a result a "true". So the regex finds something , but somehow the group method is not working.

Regex a re enabled in the Elasticsearch.yml:

script.painless.regex.enabled: true

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