ESQL_TVF()

Query an Elasticsearch cluster using ES|QL from within a MatrixOne query via the ESQL_TVF() table function. The result schema is supplied at runtime by the second argument, and the connection comes from an esql_tvf_connect() handle or the @esql_tvf_config session variable.

Description

ESQL_TVF(esql, schema, conn) sends an Elasticsearch ES|QL query to a cluster and returns the result rows as a table.

Syntax

SELECT * FROM esql_tvf(esql, schema, conn) t;

Arguments

Argument

Description

esql

The ES

schema

A JSON schema spec describing the result columns, or NULL for a schema-less single JSON-array column per row.

conn

A handle from esql_tvf_connect(config), or NULL to use the default connection from @esql_tvf_config.

Connection management

SET @h = esql_tvf_connect('{"addresses":["https://es:9200"],"username":"elastic","password":"..."}');
SELECT esql_tvf_disconnect(@h);

SET @esql_tvf_config = '{"addresses":["https://es:9200"]}';

esql_tvf_connect(config) opens (or reuses) a connection and returns a deterministic handle. esql_tvf_disconnect(handle) detaches and closes the connection. When the config is omitted or NULL, the default connection from @esql_tvf_config is used.

Examples

SELECT * FROM esql_tvf('FROM logs-* | WHERE status >= 500 | LIMIT 10', '{"cols":[{"name":"status","type":"int32"}]}', @h) t;

These examples require a reachable Elasticsearch cluster and are not paste-and-run scripts.

See Also