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:
This adapter is targeted for Elasticsearch 2.x. To use Calcite with Elasticsearch 5.x+ you can use the factory
of the adapter targeted for Elasticsearch 5.x:
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
zips. By default, Elasticsearch returns only 10 rows:
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:
This is the initial version of the Calcite Elasticsearch adapter. Work is in progress to introduce new features like aggregations into it.