{
  "id": "elasticsearch/script-compilation-too-many-dynamic",
  "signature": "ScriptException: compilation of script [my_script] failed: too many dynamic script compilations within one minute",
  "signature_zh": "脚本异常：脚本 [my_script] 编译失败：一分钟内动态脚本编译次数过多",
  "regex": "ScriptException: compilation of script \\[.*?\\] failed: too many dynamic script compilations within one minute",
  "domain": "elasticsearch",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The cluster's script compilation rate exceeds the script.max_compilations_rate limit, typically due to generating unique scripts per query instead of using cached scripts.",
  "root_cause_type": "generic",
  "root_cause_zh": "集群的脚本编译速率超过了 script.max_compilations_rate 限制，通常是因为每个查询生成唯一脚本而不是使用缓存脚本。",
  "versions": [
    {
      "version": "7.17.14",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.5.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Unlimited compilations can lead to high CPU usage, memory pressure, and potential denial of service.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This only delays the problem; if scripts are not cached, the rate will still be hit eventually with high load.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use stored scripts instead of inline scripts: POST _scripts/my_script { \"script\": { \"lang\": \"painless\", \"source\": \"doc['field'].value * params.factor\" } } then reference it in queries as \"script\": { \"id\": \"my_script\", \"params\": { \"factor\": 2 } }",
      "success_rate": 0.9,
      "how": "Use stored scripts instead of inline scripts: POST _scripts/my_script { \"script\": { \"lang\": \"painless\", \"source\": \"doc['field'].value * params.factor\" } } then reference it in queries as \"script\": { \"id\": \"my_script\", \"params\": { \"factor\": 2 } }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase the compilation rate limit temporarily: PUT /_cluster/settings { \"transient\": { \"script.max_compilations_rate\": \"100/1m\" } }",
      "success_rate": 0.75,
      "how": "Increase the compilation rate limit temporarily: PUT /_cluster/settings { \"transient\": { \"script.max_compilations_rate\": \"100/1m\" } }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用存储脚本代替内联脚本：POST _scripts/my_script { \"script\": { \"lang\": \"painless\", \"source\": \"doc['field'].value * params.factor\" } } 然后在查询中引用为 \"script\": { \"id\": \"my_script\", \"params\": { \"factor\": 2 } }",
    "临时增加编译速率限制：PUT /_cluster/settings { \"transient\": { \"script.max_compilations_rate\": \"100/1m\" } }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/scripting.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}