SELECT queries on documents of an index in Elasticsearch. Each document is returned as one row: its _source is exposed as a single column of the JSON type, and the document id and index name are available as virtual columns. The function is read-only.
Syntax
The Elasticsearch integration is experimental. Enable it with the
enable_elasticsearch setting:Arguments
The
url, index, user and password arguments can also be given in the key = value form; positional arguments fill these slots in this order, and specifying an argument both positionally and as a key (or the same key twice) is an error.
The following arguments can be specified in the key = value form (or as keys of a named collection):
In addition, the table function accepts:
The read settings
keep_alive and page_size can be passed in a trailing SETTINGS clause; see the Elasticsearch table engine for their description.
Authentication
At most one authentication method can be provided:- Basic authentication. Pass
userandpassword. - Bearer token. Pass
bearer_token. - API key. Pass
api_key.
Elasticsearch table engine or CREATE TABLE ... AS elasticsearch(...)) is registered as a dependency of the collection, so DROP NAMED COLLECTION is blocked while the table exists.
Virtual columns
_id— The document id. Type:String._index— The name of the index the document was read from. Type:LowCardinality(String).
_source is not requested from Elasticsearch. An index that does not store _source (the _source field is disabled in its mapping) can be read only through the virtual columns: a query that reads the JSON column from such an index fails with an error instead of returning empty documents.
Examples
Count the documents of an index:JSON column:
Limitations
- The function is read-only;
INSERTis not supported. - Predicates are not pushed down. A
WHEREcondition is applied in ClickHouse after the documents have been downloaded; use thequeryargument to filter on the Elasticsearch side. - The
queryis sent with thesizeof a page. A query whose result depends onsize, such as aknnquery withoutk, returns a set of documents that depends onpage_size. Specify such parameters explicitly. - Each page is a separate search request, and Elasticsearch evaluates date math such as
now-1hin thequeryanew for each request. The point in time freezes the documents but not the clock, so a time-dependentquerycan silently skip documents near the moving boundary. Use absolute dates in thequery. - Each read opens a point in time, pages through the results with
search_aftersorted by_shard_doc, and closes the point in time at the end. A page request that fails on any shard, or that times out in Elasticsearch, raises an error instead of returning partial results. - Elasticsearch 7.12 or later is required: the function relies on the point in time API and on the
_shard_docsort field, so older versions and OpenSearch reject the first request. page_sizecannot exceed theindex.max_result_windowindex setting of Elasticsearch (10000by default).