Painless script - Can't use script params as regex pattern

Hi Team,

I am trying to use regex patterns in scripts. My problem is the regex patterns are dynamic which I'll be passing it via params for script.

In elasticsearch documentation, it is specified that only way to create pattern is using forward slashes


I need to use param value for regex matching.

Please let me know if there is any option to specify the param type as Pattern
or if there is any chance to convert a string variable to a Pattern obj in painless script.

David Barnabas Jacob

This is not possible. For performance reasons, regexes must be known at compile time. You could generate your script source based on the regex, however I would be wary of this because if you have a lot of patterns, it will cause thrashing within the script cache (which has limits in place to protect from that exact scenario, you may hit "max compliations per minute).

1 Like

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