Watcher - Transform - Painless - Regular Expression / Regex - Documentation Issue?

Hi there,

at https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-painless.html you show some examples of how to use regex in a painless script. In those examples you are never using m.matches() before you call "group" or "replaceAll". I ran into a really confusing issue today, where without calling "matches" before I was not having any matching result. Is the documentation wrong or should it really be working without calling "matches" beforhands.

If it should be working without "matches", following script did not return any match to me:

    "transform" : {
      "script" : {
        "inline" : "ctx.payload.action = /(.*)/.matcher('action'); return ctx.payload"
      }
    }
"action": "java.util.regex.Matcher[pattern=(.*) region=0,6 lastmatch=]",

Thanks!
Andreas

Hey,

not sure I got your example right, just tried this, and it works

"ctx.payload.action = /foo (.*) bar/.matcher(ctx.payload.action).replaceAll('$1'); return ctx.payload"

is this what you want to do? matches() will only return a boolean, if it matches, but nothing more.

Hope this helps. If not, a fully fledged example within the execute watch API would be awesome!

--Alex

Thanks, you are right. I confused "replaceAll" and "group".

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