Type to search.

Keywords (reserved terms)

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

Keywords are reserved tokens for built-in language features in Painless. These special words have predefined meanings and cannot be used as identifiers, such as variable names, function names, or field names.

Important

In Painless documentation, "keywords" refers to reserved words in the scripting language itself. They are different from the Elasticsearch keyword field type, which is used for exact-value searches and aggregations in your data mappings.

When you write Painless scripts, keywords provide the fundamental building blocks for creating logic, defining data types, and controlling program flow. Since these words have special significance to the Painless compiler, attempting to use them for other purposes results in compilation errors.

if else while do for
in continue break return new
try catch throw this instanceof

Examples of restricted terms include if, which tells the compiler to create a conditional statement, and int, which declares an integer variable type.

Text
// Keywords used correctly for their intended purpose
int count = 0;
boolean isActive = true;
if (count > 0) {
    return count;
}
  1. `int' declares integer type
  2. 'boolean' declares boolean type, 'true' is literal
  3. 'if' creates conditional logic
  4. 'return' exits with value

If a keyword is used as an identifier Painless generates a compilation error:

Text
// These will cause compilation errors
int if = 10;
String return = "value";
boolean int = false;

// Use descriptive names instead
int count = 10;
String result = "value";
boolean isEnabled = false;
  1. Cannot use 'if' as variable name
  2. Cannot use 'return' as variable name
  3. Cannot use 'int' as variable name

These restrictions ensure that your scripts remain readable and that the Painless compiler can correctly parse your code without ambiguity.