I need to overwrite ElasticSearchConnection class to add SSL encrypted connection to Elasticsearch as the following:
if (needsHttps) {
try {
FileInputStream fileInputStream = new FileInputStream(keystorePath);
KeyStore truststore = KeyStore.getInstance("jks");
truststore.load(fileInputStream, keystorePassword.toCharArray());
SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
SSLContext sslContext = sslBuilder.build();
httpClientBuilder.setSSLContext(sslContext);
} catch (NoSuchAlgorithmException | CertificateException | KeyManagementException | KeyStoreException e) {
_logger.error("Failed to instantiate sslcontext object: \n{}", e.getMessage());
throw new SecurityException();
} catch (IOException ioe) {
_logger.error("Failed to find keystore: \n{}", ioe.getMessage());
throw new RuntimeException();
}
}