-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
spring-boot-starter-parent v2.3.1.RELEASE
elasticsearch-rest-high-level-client (version inherited from parent above)
According to spring-boot documentation:
If you have the org.elasticsearch.client:elasticsearch-rest-high-level-client dependency on the classpath, Spring Boot will auto-configure a RestHighLevelClient, which wraps any existing RestClient bean, reusing its HTTP configuration.
In our project, we have a single RestClient
bean registered in spring context:
@Bean
public RestClient elasticsearchRestClient(ElasticsearchProperties elasticsearchProperties) {
RestClientBuilder builder = RestClient.builder(
new HttpHost(elasticsearchProperties.getHost(),
elasticsearchProperties.getPort(),
elasticsearchProperties.getScheme())
);
ElasticsearchCredentials esCredentials = new ElasticsearchCredentials(elasticsearchProperties);
if (esCredentials.hasCredentials()) {
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(
esCredentials.getCredentialsProvider()));
}
return builder.build();
}
Spring actuator health endpoint returns correct response regarding connection to Elasticsearch (uses our parameters etc.).
However when we're trying to use injected RestHighLevelClient
to connect (e.g. using client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT);
it connects using default parameters from spring-boot.