# ScriptException: compile error in Painless script [my_script] - unexpected token '[' at line 5

- **ID:** `elasticsearch/script-compilation-error`
- **Domain:** elasticsearch
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 86%

## Root Cause

The Painless script contains a syntax error, such as a missing bracket, invalid operator, or incorrect array access, causing compilation failure at runtime.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.10.0 | active | — | — |
| 7.17.0 | active | — | — |
| 8.0.0 | active | — | — |
| 8.8.0 | active | — | — |

## Workarounds

1. **Debug the script using the Painless execute API: POST _scripts/painless/_execute { "script": { "source": "return doc['field'].value;", "lang": "painless" } } to isolate the syntax issue.** (90% success)
   ```
   Debug the script using the Painless execute API: POST _scripts/painless/_execute { "script": { "source": "return doc['field'].value;", "lang": "painless" } } to isolate the syntax issue.
   ```
2. **Rewrite the script to avoid complex array access by using helper methods, e.g., replace `list[0]` with `list.get(0)`.** (85% success)
   ```
   Rewrite the script to avoid complex array access by using helper methods, e.g., replace `list[0]` with `list.get(0)`.
   ```
3. **Enable script compilation logging to see full error details: PUT _cluster/settings { "transient": { "logger.org.elasticsearch.script": "DEBUG" } }** (75% success)
   ```
   Enable script compilation logging to see full error details: PUT _cluster/settings { "transient": { "logger.org.elasticsearch.script": "DEBUG" } }
   ```

## Dead Ends

- **** — The error is a syntax token issue, not precedence. Adding parentheses may mask the real problem or introduce new errors. (70% fail)
- **** — This reduces performance significantly and does not fix the syntax error in the script itself. (90% fail)
- **** — Upgrading does not fix the script's syntax; it only changes how the error is reported. The root cause remains. (80% fail)
