Introduction to Painless | Elastic Docs (original) (raw)

Serverless Stack

Tip

This introduction is designed for users new to Painless scripting. If you're already familiar with Painless, refer to the Painless language specification for syntax details and advanced features.

Painless is a secure, performant, and flexible scripting language designed specifically for Elasticsearch. As the default scripting language for Elasticsearch, Painless lets you safely customize search behavior, data processing, and operations workflows across your {[stack]} deployments.

What is Painless?

Painless was introduced in Elasticsearch 5.0 as a replacement for Groovy, with improved security and performance compared to previous scripting solutions. Built on the Java Virtual Machine (JVM), Painless provides the familiar syntax of Java while improving the security boundaries with guardrails and a sandbox environment.

Unlike general scripting languages, Painless is purpose-built for Elasticsearch, enabling native performance while preventing unauthorized access to system resources. This architecture makes Painless both powerful for data manipulation and safe for production environments.

Common use cases include creating new fields based on existing data, calculating time differences between dates, extracting structured data from log messages, and implementing custom business logic in search scoring. For more examples, refer to our step-by-step tutorials.

Benefits

Painless enables scripting in various contexts throughout Elasticsearch, such as:

Search enhancement

Data processing

Operational automation

How it works

You can write Painless scripts inline for quick operations or create reusable functions for your data operation. Here’s a sample Painless script applied to data transformation:

`String productTitle(String manufacturer, String productName) { return manufacturer + " - " + productName; }

return productTitle("Elitelligence", "Winter jacket"); `

This script demonstrates a few facets of Painless scripting:

Painless provides three core benefits across all scripting contexts:

Where to write in Painless

You can use Painless in multiple contexts throughout Elasticsearch:

Start scripting

Write your first Painless script by trying out our guide or jump into one of our tutorials for real-world examples using sample data.

For complete syntax and language features, refer to the Painless language specification.