Establishing a Connection Using the JDBC Driver Manager
The examples in this section show you how to establish a connection to an Elasticsearch index and cluster, using the JDBC Driver Manager.
First, the following code shows how you pass the required property "installDir" and use the JDBC Driver Manager to create a connection to a locally installed Elasticsearch and the index orders.
String url = "jdbc:evp:elasticsearch:5.6.4://localhost:9300/cluster_name/orders";
Properties info = new Properties();
info.setProperty("installDir", path_to_JDBC_driver_installation_directory);
If the Elasticsearch instance you are connecting to is enabled for Secure Sockets Layer (SSL) with the Search Guard plugin, you must pass these additional properties:
info.setProperty("useSSL", true);
info.setProperty("keystore", "path_to_the_JKS_keystore_file");
info.setProperty("keystorePassword", "unencrypted_JKS_keystore_password");
info.setProperty("truststore", "path_to_the_JKS_truststore_file");
info.setProperty("truststorePassword", "unencrypted_JKS_truststore_password")
Then, use the following code to establish the connection:
try (Connection connection = DriverManager.getConnection(url, info)) {
assertTrue(connection != null);
}