# \[script\] Too many dynamic script compilations within one minute, max: \[15/min\]

**URL:** <https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406>\
**Category:** Elasticsearch\
**Created:** [April 25, 2018, 5:20am UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406 "2018-04-25T05:20:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoopvalluthadam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopvalluthadam/32/30286_2.png) [@anoopvalluthadam](https://discuss.elastic.co/u/anoopvalluthadam)\
**Post date:** [April 25, 2018, 5:20am UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/1 "2018-04-25T05:20:44Z")

</div>

I have almost 10K of scripts like this:

```
POST _scripts/536672d3cface3ddbb63666bf1b6030f
{
  "script": {
      "lang": "painless",
      "source": "Pattern p = /\\s?a\\S*?/i; p.matcher(params._source.summary ?: '').find();"
   }
}

```

Query:

```
{
   "query": {
      "bool": {
         "must": [
            {
               "bool": {
                  "must": [
                     {
                        "query_string": {
                           "query": "a*",
                           "quote_analyzer": "standard",
                           "allow_leading_wildcard": "true",
                           "analyze_wildcard": "true",
                           "default_operator": "AND",
                           "phrase_slop": 1
                        }
                     },
                     {
                        "script": {
                           "script": {
                              "id": "536672d3cface3ddbb63666bf1b6030f"
                           }
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

```

everything stored in a percolator, when it is getting percolated I am getting `[script] Too many dynamic script compilations within one minute, max: [15/min]`.

I have changed from 15 to 5000, of course our executions are more than 500 / minutes and failing.

In anyway we can handle this error

Or or requirement is support wildcards like our users will search for `aus* gov*` , `aus* poli* blah*` or any combination of wildcard with multiple words.

other than scripting any other way to support wildcard search?

Tried with ngrams and edge-ngrams, but it is not the perfect match and ended in script, but it is failing here.

Script with parameter won't work with `Pattern` otherwise I could have used parameterized scripts!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 27, 2018, 4:04pm UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/2 "2018-04-27T16:04:26Z")

</div>

A script should not be needed here. While it will be just as inefficient from a query perspective, have you tried the [regex query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html)?

---

<div class="post-metadata">

**Author:** ![anoopvalluthadam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopvalluthadam/32/30286_2.png) [@anoopvalluthadam](https://discuss.elastic.co/u/anoopvalluthadam)\
**Post date:** [April 30, 2018, 7:06am UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/3 "2018-04-30T07:06:37Z")

</div>

> [@anoopvalluthadam](#):
>
> aus\* gov\* , aus\* poli\* blah\* or any combination of wildcard with multiple words.

didn't work with `aus* gov*` , `aus* poli* blah*` or any combination of wildcard with multiple words.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 30, 2018, 8:14am UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/4 "2018-04-30T08:14:03Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 30, 2018, 4:14pm UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/5 "2018-04-30T16:14:13Z")

</div>

> didn't work with aus\* gov\*

A couple things to note:

- If these are meant to be multiple terms, they need to be in multiple clauses. Ie if you are trying to match documents with the terms beginning with `aus` and terms beginning with `gov` you need need a `bool` query with a must clause for each. In this case, a `prefix_query` would be best.
- Putting `aus*` into a regex query won't work. That is the query string syntax for a prefix query. Please read the full documentation for the regex query I liked previously. In this case, the pattern would look something like `aus.*` (but again, this particular query would be better as a `prefix_query`).

---

<div class="post-metadata">

**Author:** ![anoopvalluthadam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopvalluthadam/32/30286_2.png) [@anoopvalluthadam](https://discuss.elastic.co/u/anoopvalluthadam)\
**Post date:** [May 4, 2018, 3:21am UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/6 "2018-05-04T03:21:04Z")

</div>

problem is not `aus*` it is `aus* gov*`. It is a phrase. I wanted to match a phrase if we use boolean it will batch the words not as a phrase. isn't it?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 20, 2018, 9:23pm UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/7 "2018-05-20T21:23:34Z")

</div>

If you want to do phrase matching with wildcards, you should probably look at [span queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html). But do so with caution: phrase and wildcards are much slower than normal queries, and combining them will perform even worse.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 17, 2018, 9:23pm UTC](https://discuss.elastic.co/t/script-too-many-dynamic-script-compilations-within-one-minute-max-15-min/129406/8 "2018-06-17T21:23:43Z")

</div>

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