Painless scripting language
This section introduces Painless syntax and advanced features. If you're new to Painless scripting, start with our introduction for fundamentals and examples.
Painless is the default scripting language for Elasticsearch, designed for security, performance, and flexibility. Built on the Java Virtual Machine (JVM), Painless provides Java-like syntax with direct compilation, a sandbox environment with fine-grained allowlists, and context-aware scripting across the Elastic Stack.
Painless compiles directly to JVM bytecode, enabling native performance while maintaining security boundaries through fine-grained allowlists and a sandbox environment. The language implements a subset of Java syntax with Elasticsearch extensions, supporting field access patterns, datetime operations, and nested data manipulation across context-aware execution workloads.
Scripts execute within specific contexts that control available variables, allowed operations, and execution environments. Different contexts provide APIs for their specific use case.
Painless provides three core benefits:
- Security: Fine-grained allowlists that prevent access to restricted Java APIs and enforce security layers through a sandbox environment and JVM-level protection
- Performance: Native compilation eliminates interpretation overhead and leverages JVM optimization, delivering native execution speed for production environments
- Flexibility: Scripting syntax and execution contexts span the Elasticsearch stack, from search scoring and data processing to operational processing
The reference documentation includes the following resources:
- Language specification: syntax, operators, data types, and compilation semantics
- Contexts: Execution environments, available variables, and context-specific APIs
- API examples: Examples of how to run the Painless execute API to build and test scripts.
- Debugging & Troubleshooting: Debugging techniques, common errors, and solutions
For step-by-step tutorials and real-world examples, refer to How to write Painless scripts and Painless script tutorials in the Explore and Analyze section.