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
/[pattern]/
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.
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).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.