Regular expression as a parameter in painless

   {
   "query": {
      "bool": {
         "must": [
            {
               "query_string": {
                  "query": "a*",
                  "quote_analyzer": "standard",
                  "allow_leading_wildcard": "true",
                  "analyze_wildcard": "true",
                  "default_operator": "AND",
                  "phrase_slop": 1
               }
            },
            {
               "script": {
                  "script": {
                     "source": "Pattern p =  /\\s?a\\S*?/i;   p.matcher(params._source.summary ?: '').find();",
                     "lang": "painless"
                  }
               }
            }
         ]
      }
   }
}

I want the above query to parameterize because sometimes I am getting an error

[script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_per_minute]

If we go for index script or file-based script will it help to remove this error?

1 Like

Regexes are compile time constants because allowing them to be defined at runtime would mean regex compiling per document (ie possibly millions of regex compilations).

While it is not advised and should be used with care, especially with the very short prefix you are using, why not use the prefix query?

NOTE: all the queries are saved in the percolator and we are doing a search in percolator

I use this script to support wildcard searches of all combination

aus * gov*
polic*
*alia *ment

Like these all combination

If I use Prefix query | Elasticsearch Guide [8.11] | Elastic does it help me to solve these requirements. I was using ngrams and edge-ngrams, but uses lot of spaces.

If I increase script.max_compilations_per_minute to 1000 or more, of-course it will impact the performance but at what level?

I am also facing "max_compilations_per_minute" error.
This is mainly happening due to painless script we are using in in search queries registered as percolator.
re-indexing of data is not an option for us.
How can we avoid this circuit break exception happening mainly due to "max_compilations_per_minute".

Alternative or worst solution:-
Is there any max limit for setting "max_compilations_per_minute" recommended.

1 Like

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