elasticsearch
Loading

Operators

Serverless Stack

Operators are the fundamental building blocks for data manipulation in Painless scripts. They enable calculations, comparisons, logical operations, and data access across all Elasticsearch scripting contexts.

An operator performs a specific action to evaluate values in a script. An expression combines one or more operators to produce a result. Precedence determines evaluation order when multiple operators are present, while associativity controls evaluation direction for operators with equal precedence.

Painless operators use Java-like syntax with Elasticsearch specific enhancements such as null-safe navigation and specialized data structure access.

Painless organizes operators into five functional categories based on their purpose.

Painless operator categories

Double-click to expand the image.

Control the fundamental flow and structure of expressions in Painless scripts. These operators manage how expressions are evaluated, values are assigned, and conditional logic is run.

  • Precedence (): Controls evaluation order by overriding default precedence rules
  • Function call (): Executes user-defined functions with arguments
  • Cast () : Forces explicit type conversion between compatible types
  • Conditional ? : : Provides inline if-else logic for expressions
  • Elvis ?: : Returns first non-null value for null coalescing
  • Assignment = : Stores values in variables or fields
  • Compound assignment $= : Combines binary operations with assignment (+=, -=, and so on)

Perform mathematical calculations and bit-level manipulations on numeric values. These operators handle arithmetic, bitwise operations, and value modifications essential for numerical computations.

Handle logical evaluation, comparisons, and conditional expressions. These operators are fundamental for creating filters, conditional logic, and boolean expressions in scripts

  • Boolean not !:Inverts boolean values (true becomes false)
  • Comparison > >= < <= : Compares numeric values for ordering
  • Instanceof instanceof: Checks if an object is an instance of a specific type
  • Equality == != : Compares values for equality (calls equals() method)
  • Identity === !== : Compares object references for same instance
  • Boolean xor ^: Returns true if exactly one operand is true
  • Boolean and &&: Returns true only if both operands are true
  • Boolean or ||: Returns true if at least one operand is true

Enable interaction with objects, method calls, and data structure manipulation. These operators are essential for working with documents, collections, and complex data types in Elasticsearch contexts.

  • Method call . (): Invokes methods on objects with optional arguments
  • Field access .: Accesses object properties and member fields
  • Null safe ?.: Safely accesses fields/methods without null pointer exceptions
  • List/Map initialization [] [:]: Creates new List or Map collections with initial values
  • List/Map access []: Retrieves or sets elements in collections by key/index
  • New instance new (): Creates new object instances with constructor arguments
  • String concatenation + : Joins strings and converts other types to strings

Provide specialized functionality for array creation, element access, and array property retrieval. These operators are essential when working with multi-value fields and array data structures.

Operator Category Symbol(s) Precedence Associativity
Precedence General () 0 left → right
Method call Reference . () 1 left → right
Field access Reference . 1 left → right
Null safe Reference ?. 1 left → right
Function call General () 1 left → right
Array initialization Array [] {} 1 left → right
Array access Array [] 1 left → right
Array length Array . 1 left → right
List initialization Reference [] 1 left → right
List access Reference [] 1 left → right
Map initialization Reference [:] 1 left → right
Map access Reference [] 1 left → right
Post increment Numeric ++ 1 left → right
Post decrement Numeric 1 left → right
Pre increment Numeric ++ 2 right → left
Pre decrement Numeric 2 right → left
Unary positive Numeric + 2 right → left
Unary negative Numeric - 2 right → left
Boolean not Boolean ! 2 right → left
Bitwise not Numeric ~ 2 right → left
Cast General () 3 right → left
New instance Reference new () 3 right → left
New array Array new [] 3 right → left
Multiplication Numeric * 4 left → right
Division Numeric / 4 left → right
Remainder Numeric % 4 left → right
String concatenation Reference + 5 left → right
Addition Numeric + 5 left → right
Subtraction Numeric - 5 left → right
Left shift Numeric << 6 left → right
Right shift Numeric >> 6 left → right
Unsigned right shift Numeric >>> 6 left → right
Greater than Boolean > 7 left → right
Greater than Or Equal Boolean >= 7 left → right
Less than Boolean < 7 left → right
Less than Or Equal Boolean <= 7 left → right
Instanceof Boolean instanceof 8 left → right
Equality equals Boolean == 9 left → right
Equality not equals Boolean != 9 left → right
Identity equals Boolean === 9 left → right
Identity not equals Boolean !== 9 left → right
Bitwise and Numeric & 10 left → right
Boolean xor Boolean ^ 11 left → right
Bitwise xor Numeric ^ 11 left → right
Bitwise or Numeric | 12 left → right
Boolean and Boolean && 13 left → right
Boolean or Boolean || 14 left → right
Conditional General ? : 15 right → left
Elvis General ?: 16 right → left
Assignment General = 17 right → left
Compound assignment General $= 17 right → left