This is a cache of https://www.elastic.co/guide/en/elasticsearch/painless/8.19/painless-lambdas.html. It is a snapshot of the page as it appeared on 2025-11-22T03:24:11.432+0000.
Lambdas | Painless Scripting Language [8.<strong>19</strong>] | Elastic
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Lambdas

edit

Lambda expressions and method references work the same as in Java.

list.removeIf(item -> item == 2);
list.removeIf((int item) -> item == 2);
list.removeIf((int item) -> { item == 2 });
list.sort((x, y) -> x - y);
list.sort(Integer::compare);

You can make method references to functions within the script with this, for example list.sort(this::mycompare).