Literals
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability 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.
Serverless
Generally available
Stack
Generally available
Literals represent fixed values in your code that are directly written into your script. Unlike variables, literals have constant values that cannot be changed during script runtime. The three supported types of literals are: integers, floats, and strings.
Use an integer literal to specify an integer-type value in decimal, octal, or hex notation of a primitive type int, long, float, or double. Use the following single-letter designations to specify the primitive type: l or L for long, f or F for float, and d or D for double. If not specified, the type defaults to int. Use 0 as a prefix to specify an integer literal as octal, and use 0x or 0X as a prefix to specify an integer literal as hex.
INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
OCTAL: '-'? '0' [0-7]+ [lL]?;
HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
Integer literals
Text int i = 0; double d = 0D; long l = 1234L; float f = -90f; int e = -022; int x = 0xF2A;int 0double 0.0long 1234float -90.0int -18 in octalint 3882 in hex
Use a floating-point literal to specify a floating-point-type value of a primitive type float or double. Use the following single-letter designations to specify the primitive type: f or F for float and d or D for double. If not specified, the type defaults to double.
DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?;
EXPONENT: ( [eE] [+\-]? [0-9]+ );
Floating point literals
Text double b = 0.0; double d = 1E6; double c = 0.977777; double n = -126.34; float f = 89.9F;double 0.0double 1000000.0in exponent notationdouble 0.977777double -126.34float 89.9
Use a string literal to specify a string type value with either single-quotes or double-quotes. A string literal is specified as String because in Java and Painless this isn't a primitive type. Use a " token to include a double-quote as part of a double-quoted string literal. Use a ' token to include a single-quote as part of a single-quoted string literal. Use a \\ token to include a backslash as part of any string literal.
STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
| ( '\'' ( '\\\'' | '\\\\' | ~[\\'] )*? '\'' );
String literals using single-quotes
Text String a = 'single-quoted string literal'; String b = '\'single-quoted with escaped single-quotes\' and backslash \\'; String c = 'single-quoted with non-escaped "double-quotes"';String literals using double-quotes
Text String a = "double-quoted string literal"; String b = "\"double-quoted with escaped double-quotes\" and backslash: \\"; String c = "double-quoted with non-escaped 'single-quotes'";
Character literals are not specified directly in Painless. Instead, use the cast operator to convert a String type value into a char type value.
For detailed information about character types, casting, and usage, refer to Character type usage.