Elasticsearch RestClient 7.4 - making SSL connection

HI, I am trying to connect to the elasticsearch server using basic credentials and receiving the "Unrecognized SSL message, plaintext connection?" error.

Appreciate your help. Thanks!

if (restClient == null) {
		try {
			Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), new BasicHeader("Role", "Read")};
			final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
			credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("email@domain.com", "password"));

					restClient = RestClient.builder(new HttpHost("myhost", "9200" "https")).setDefaultHeaders(headers)
					.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
						public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
							httpClientBuilder.disableAuthCaching(); //if received 401 , then try sending authentication, if not,reuse previous credentials.
							
							return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
						}
					}).build();

		}catch (Exception e	){
			System.out.println("Error Creating RestClient:" + e.getMessage());
		}

	}
return restClient;
}

Does your Elasticsearch cluster have TLS/https enabled? If not, you might need to change the HttpHost parameter from https to http.

--Alex

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