Elasticsearch adapter
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
types in
Elasticsearch. The schema/database is represented by the index
parameter
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
Elasticsearch via sqlline
as
follows:
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
named zips
under index named usa
.
We can issue a simple query to fetch the names of all the states
stored in the type zips
.
While executing this query, the Elasticsearch adapter is able to recognize
that 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 COUNT
, 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.
Supported versions
Currently this adapter supports ElasticSearch versions 2.x (or newer). Generally we try to follow official support schedule.