ElasticsearchJestHealthIndicator:在 spring 引导中使用 Jest 时运行状况检查失败

ElasticsearchJestHealthIndicator : Health check failed when using Jest in spring boot

我在我的 spring 启动应用程序中 enter link description here 使用 Jest。

然后我用示例代码创建了客户端:

JestClientFactory factory = new JestClientFactory();
 factory.setHttpClientConfig(new HttpClientConfig
                        .Builder("http://myhost:9200")
                        .multiThreaded(true)
 
 JestClient client = factory.getObject();

一切都很好。我可以使用这个客户端来完成我想要的所有查询。开心到现在

那么问题来了,当应用程序启动时,ElasticsearchJestHealthIndicator class 是自动初始化的。但问题是我不知道在哪里设置它需要的配置,所以它使用默认值 http://localhost:9200,这导致我遇到这个问题:

WARN [on(2)-127.0.0.1] s.b.a.h.ElasticsearchJestHealthIndicator : Health check failed io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://localhost:9200 at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:70) at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:60)

有人可以告诉我如何正确配置或关闭它吗?

在参考文档中的快速搜索显示 Spring Boot 将为您配置一个 JestClient(您可以将其注入任何需要的位置),并且应用以下配置属性:

spring.elasticsearch.jest.uris=http://search.example.com:9200
spring.elasticsearch.jest.read-timeout=10000
spring.elasticsearch.jest.username=user
spring.elasticsearch.jest.password=secret

参见here for more on this

The Jest client has been deprecated as well, since both Elasticsearch and Spring Data Elasticsearch provide official support for REST clients.

https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-elasticsearch