Java connection lost

I'm trying to connect to my Elasticsearch node from Java.
I have this code :

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "pass"));

            Path trustStorePath = Paths.get("/home/name/certCA.p12");
            KeyStore truststore = KeyStore.getInstance("pkcs12");

            try (InputStream is = Files.newInputStream(trustStorePath)) {
                truststore.load(is, null);

            SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);
            final SSLContext sslContext =;

            RestHighLevelClient client = new RestHighLevelClient(
                            new HttpHost("", 9200, "https")).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {

                        public HttpAsyncClientBuilder customizeHttpClient(
                                final HttpAsyncClientBuilder httpAsyncClientBuilder) {

                            return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setSSLContext(sslContext);




After I run it I get error with connection is closed.
Any idea?
Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.