Elasticsearch’s SQL jdbc driver is a rich, fully featured JDBC driver for Elasticsearch. It is Type 4 driver, meaning it is a platform independent, stand-alone, Direct to Database, pure Java driver that converts JDBC calls to Elasticsearch SQL.
The JDBC driver can be obtained from:
<dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>x-pack-sql-jdbc</artifactId> <version>7.0.1</version> </dependency>
from artifacts.elastic.co/maven
by adding it to the repositories list:
<repositories> <repository> <id>elastic.co</id> <url>https://artifacts.elastic.co/maven</url> </repository> </repositories>
The driver main class is org.elasticsearch.xpack.sql.jdbc.EsDriver
.
Note the driver implements the JDBC 4.0 Service Provider
mechanism meaning it is registered automatically
as long as it is available in the classpath.
Once registered, the driver understands the following syntax as an URL:
jdbc:es://[[http|https]://]*[host[:port]]*/[prefix]*<[?[option=value]&]*
jdbc:es://
[[http|https]://]
http
(default) or https
. Optional.
[host[:port]]
localhost
by default) and port (9200
by default).
Optional.
[prefix]
[option=value]
The driver recognized the following properties:
timezone
(default JVM timezone)
ID
.
Highly recommended to set it (to, say, UTC
) as the JVM timezone can vary, is global for the entire JVM and can’t be changed easily when running under a security manager.
connect.timeout
(default 30s)
network.timeout
(default 60s)
page.timeout
(default 45s)
page.size
(default 1000)
query.timeout
(default 90s)
user
password
ssl
(default false)
ssl.keystore.location
ssl.keystore.pass
ssl.keystore.type
(default JKS
)
PKCS12
is a common, alternative format
ssl.truststore.location
ssl.truststore.pass
ssl.truststore.type
(default JKS
)
PKCS12
is a common, alternative format
ssl.protocol
(default TLS
)
proxy.http
proxy.socks
field.multi.value.leniency
(default true
)
validate.properties
(default true)
To put all of it together, the following URL:
jdbc:es://http://server:3456/?timezone=UTC&page.size=250
Opens up a Elasticsearch SQL connection to server
on port 3456
, setting the JDBC connection timezone to UTC
and its pagesize to 250
entries.