Elasticsearch RestHighLevelClient behind a corporate firewall via a proxy

I am trying to access cloud Elasticsearch installation from our network that requires using a proxy for external requests. This is the snippet of code I use to pass Elasticsearch credentials and our proxy settings:

CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(elasticUser, elasticPassword));

RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName,port,"https")).setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setProxy(new HttpHost(proxyURL", proxyPort, "http")));

RestHighLevelClient client = new RestHighLevelClient(restClientBuilder);

This results in this response from ES:

"Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=security_exception, reason=action [indices:data/read/search] requires authentication]]"

It appears that Elasticsearch credentials are not passed for some reason.

should have been done like this:

	RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName, port, "https"))
		.setHttpClientConfigCallback(clientBuilder -> {
		  clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
		  clientBuilder.setProxy(new HttpHost(proxyURL, proxyPort, "http"));
		  return clientBuilder;
		 });
1 Like

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