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
The model gives Calcite the necessary parameters to create an instance
of the Elasticsearch adapter. The models can contain
The name of the tables defined in the model definition corresponds to
Elasticsearch. The schema/database is represented by the
in the model definition.
A basic example of a model file is given below:
Assuming this file is stored as
model.json, you can connect to
sqlline will now accept SQL queries which access your Elasticsearch types.
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.
For example, in the example dataset there is an Elasticsearch type
zips under index named
We can issue a simple query to fetch the names of all the states
stored in the type
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 2.x (or newer). Generally we try to follow official support schedule.