For instructions on downloading and building Calcite, start with the tutorial.
Once you’ve managed to compile the project, you can return here to start querying Elasticsearch with Calcite. First, we need a model definition. The model gives Calcite the necessary parameters to create an instance of the Elasticsearch adapter. The models can contain definitions of materializations. The name of the tables defined in the model definition corresponds to indices in Elasticsearch.
A basic example of a model file is given below:
Assuming this file is stored as
model.json, you can connect to
You can also specify the index name that is represented by the
index parameter in the model definition:
sqlline will now accept SQL queries which access your Elasticsearch.
The purpose of this adapter is to compile the query into the most efficient
Elasticsearch SEARCH JSON possible by exploiting filtering and sorting directly
in Elasticsearch where possible.
We can issue a simple query to fetch the names of all the states
stored in the index
While executing this query, the Elasticsearch adapter is able to recognize
city can be filtered by Elasticsearch and
state can be sorted by
Elasticsearch in ascending order.
The final source json given to Elasticsearch is below:
You can also query elastic search index without prior view definition:
Use of Scrolling API
For queries without aggregate functions (like
MAX etc.) elastic adapter
uses scroll API, by default.
This ensures that consistent and full data-set is returned to end user (lazily and in batches). Please note that
scroll is automatically cleared (removed) when all query resuts are consumed.
Currently this adapter supports ElasticSearch versions 6.x (or newer). Generally we try to follow official support schedule. Also, types are not supported (this adapter only supports indices).