I had a same issue and I figured out what was a problem.
For the health check java spring boot uses RestClient where I was using HighLevelRestClient for ES indexing/searching/deleting.
So, it seems you have also same case, whether you are using high or low (or tcp) level client for ES query but health check requires RestClient.
So, the solution is to override RestClient bean with your env params. Add following to your configuration file (replace environment values with yours):
@Bean(destroyMethod = "close")
public RestClient restClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(
environment.getProperty("elasticsearch.username"),
environment.getProperty("elasticsearch.password")));
List<HttpHost> hosts = new ArrayList<>();
hosts.add(new HttpHost(
environment.getProperty("elasticsearch.hosts.host.name", String.class),
environment.getProperty("elasticsearch.hosts.host.port", Integer.class),
"http"));
LOGGER.info("Elasticsearch connection establishing..." + hosts.toArray().toString());
return RestClient.builder(Iterables.toArray(hosts, HttpHost.class))
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
}
Let me see (plz post) your configuration if this does not work.
Good luck!
References