Loading

How to write Painless scripts

Serverless Stack

Tip

This guide provides a beginner-friendly introduction to Painless scripting with step-by-step tutorials and practical examples. If you're new to scripting or Painless, this is the recommended starting point.

For users with Java or Painless experience looking for technical specifications and advanced features, refer to A Brief Painless walkthrough in the Reference section.

Wherever scripting is supported in the Elasticsearch APIs, the syntax follows the same pattern; you specify the language of your script, provide the script logic (or source), and add parameters that are passed into the script:

"script": {
  "lang":   "...",
  "source" | "id": "...",
  "params": { ... }
}
		
lang
Specifies the language the script is written in. Defaults to painless.
source, id
The script itself, which you specify as source for an inline script or id for a stored script. Use the stored script APIs to create and manage stored scripts.
params
Specifies any named parameters that are passed into the script as variables. Use parameters instead of hard-coded values to decrease compile time.

Get started with Painless scripting: