0

I am trying to connect to an existing Elasticsearch instance. The instance is set up and working fine, which I can confirm by accessing it through the browser under https://localhost:9200. I am using Spring Data Elasticsearch version 4.1.2 and I am following the official instructions from https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.rest.

Unfortunately, when starting the application, the initial health checks of the elasticsearch instance fail, because the code is trying to use http instead of https:

o.s.w.r.f.client.ExchangeFunctions       : [377e90b0] HTTP HEAD http://localhost:9200/

Therefore I added the ".usingSsl()" to the ClientConfiguration, but it does not seem to have any effect and I just don't understand why. The "funny" thing is, if I implement the reactive client as described here (https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.reactive), https suddenly works and the applications starts perfectly fine. However, I want to use the regular high level client.

Can you help me change the configuration in a way so that it finally makes use of https instead of http?

@Configuration
class ElasticsearchClientConfig: AbstractElasticsearchConfiguration() {
    
    @Bean
    override fun elasticsearchClient(): RestHighLevelClient {
           val clientConfiguration = ClientConfiguration.builder()
                 .connectedTo("localhost:9200")
                 .usingSsl()
                 .build();

        return RestClients.create(clientConfiguration).rest();
    }
}
pjung
  • 1
  • do you use the reactive stack or the imperative one? – P.J.Meisch May 17 '21 at 20:08
  • I am using the reactive stack (spring-boot-starter-webflux 2.4.1), but I was hoping I could still use the non-reactive way for this. Im still new to the reactive world of java to be honest. – pjung May 17 '21 at 20:19
  • it does not make sense to start a reactive application and then use imperative blocking code, that will block your whole application. Reactive apps are started with a minimal number of threads, blocking calls will very soon block your whole application. – P.J.Meisch May 17 '21 at 21:20

0 Answers0