Using ES|QL functions
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Using ES|QL functions
editThe ES|QL language includes a rich set of functions that can be used in expressions and conditionals. These can be included in expressions given as strings, as shown in the example below:
from elasticsearch.esql import ESQL # FROM employees # | KEEP first_name, last_name, height # | WHERE LENGTH(first_name) < 4" query = ( ESQL.from_("employees") .keep("first_name", "last_name", "height") .where("LENGTH(first_name) < 4") )
All available ES|QL functions have Python wrappers in the elasticsearch.esql.functions
module, which can be used when building expressions using Python syntax. Below is the example above coded using Python syntax:
from elasticsearch.esql import ESQL, functions # FROM employees # | KEEP first_name, last_name, height # | WHERE LENGTH(first_name) < 4" query = ( ESQL.from_("employees") .keep("first_name", "last_name", "height") .where(functions.length(E("first_name")) < 4) )
Note that arguments passed to functions are assumed to be literals. When passing field names, parameters or other ES|QL expressions, it is necessary to wrap them with the E()
helper function so that they are interpreted correctly.
You can find the complete list of available functions in the Python client’s ES|QL API reference documentation.