Type to search.

Comments

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.

Comments are used to explain or annotate code and make it more readable. They are ignored when the script is executed, allowing you to add notes or temporarily disable code sections without affecting the functionality.

Painless supports two types of comments: single-line comments and multi-line comments.

Single-line comments start with // and continue to the end of the line. Everything after // on that line is ignored by the compiler.

Text
SINGLE_LINE_COMMENT: '//' .*? [\n\r];
Text
// This is a single-line comment
int value = 10;
int price = 100;
  1. Comment at the end of a line

Multi-line comments start with /* and end with */. Everything between these markers is ignored, even if it spans multiple lines.

Text
MULTI_LINE_COMMENT: '/*' .*? '*/';
Text
/* This is a
   multi-line comment
   spanning several lines */

int total = price * quantity;

/* You can also use multi-line comments
   to temporarily disable code blocks:

int debugValue = 0;
debugValue = calculateDebug();
*/

int result = /* inline comment */ calculateTotal();

Use comments to:

  • Explain complex logic or business rules
  • Document function parameters and return values
  • Provide context data transformations
  • Temporarily disable code during development
Tip

Good comments explain why something is done, not just what is being done. The code itself should be clear enough to show what it does.