7

I am getting below error in elasticsearch.

{"error":{"root_cause":[{"type":"circuit_breaking_exception","reason":"[script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting","bytes_wanted":0,"bytes_limit":0}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"en_product_idx2","node":"eFSrhLqNTYubukyF3pz8aw","reason":{"type":"query_shard_exception","reason":"script_score: the script could not be loaded","index_uuid":"IFYbHBBjRxW188SKVh0c4Q","index":"en_product_idx2","caused_by":{"type":"general_script_exception","reason":"Failed to compile inline script [if (params['_source']['sku'] == \"black\") return 999; else return 434-params.ids.indexOf(doc['id'].value.intValue());] using lang [painless]","caused_by":{"type":"circuit_breaking_exception","reason":"[script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting","bytes_wanted":0,"bytes_limit":0}}}}],"caused_by":{"type":"circuit_breaking_exception","reason":"[script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_rate] setting","bytes_wanted":0,"bytes_limit":0}},"status":400}

Mark Whitaker
  • 8,465
  • 8
  • 44
  • 68
anjanbarik
  • 71
  • 1
  • 1
  • 4

3 Answers3

4

@anjanbarik solution is correct, I don't want to take away merit.. But instead of "transient" it's better to use "persistent", if not the changes will be gone after a full cluster restart.

You can use any of the below requests to apply the changes:

  • Using curl: curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'{ "persistent": {"script.max_compilations_rate": "200/10m"}}'

  • Using Dev Console:

PUT _cluster/settings
{
    "persistent" : {
        "script.max_compilations_rate" : "200/10m"
    }
}
kevn_gonz
  • 41
  • 5
1

Scripting is not normal behavior, because the script needs to be compiled, there is a limit on the number of inline script compilations within a period of time.

Script compilation circuit breaker

You can follow the "prefer-parameters" section of the scripting documentation for more information.

Honarkhah
  • 553
  • 7
  • 19
0

parameterize the script

My issue was that I neglected to parameterize my script properly and was interpolating a list into the script:

broken script manually injecting the prop_groups into the script:

if (doc.containsKey('prop_groups') && doc['prop_groups'].length > 0) {{
    int[] prop_groups = new int[] {{{', '.join([str(x) for x in prop_groups])}}}; 
    for(int i = 0; i < doc['prop_groups'].length; i++) 

Fixed, using params.prop_groups:

if (doc.containsKey('prop_groups') && doc['prop_groups'].length > 0) {{ 
    for(int i = 0; i < doc['prop_groups'].length; i++) 
    {{
        for(int j = 0; j < params['prop_groups'].length; j++) 

Passing in the params:

        return {
            "script": {
                "source": script,
                "params": {"prop_groups": [str(x) for x in prop_groups]},
            }
        }
jmunsch
  • 22,771
  • 11
  • 93
  • 114