【问题标题】:Elasticsearch Client is defaulting to localhostElasticsearch 客户端默认为 localhost
【发布时间】:2021-11-27 21:54:31
【问题描述】:

我在我的 Spring Boot (2.5.4) 应用程序中使用 spring.data.elasticsearch 和 Elasticsearch 7.14.1。

我的 application.properties 是这样的

spring.elasticsearch.rest.uris=elasticsearch:9200
spring.data.elasticsearch.cluster=elasticsearch:9200
spring.data.elasticsearch.repositories.enabled=true

只要调用来自本地主机,就可以正常工作,没有问题。但是,当我尝试启动我的 Spring Boot 容器时,我看到 NoReachableHostException 失败

    reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
blah-blah-service 
 Caused by: org.springframework.data.elasticsearch.client.NoReachableHostException: Host **'localhost:9200'** not reachable. Cluster state is offline.
blah-blah-service         
 at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider.lambda$lookupActiveHost$3(SingleNodeHostProvider.java:101) 

显然,无论出于何种原因,我建议使用“elasticsearch”主机(定义的网络,已测试并可从 docker 容器内部和外部访问)并没有很好地与 Spring Data 配合使用。我什至用过

@PropertySource("classpath:mysearch.properties")

在我的应用程序中尝试将这些属性引入应用程序,但看起来没有任何效果。我的 Elasticsearch 配置中是否缺少某些内容?

PS:我在容器内锻炼了curl http://elasticsearch:9200,没有发现任何问题

【问题讨论】:

    标签: java spring-boot elasticsearch spring-data-elasticsearch


    【解决方案1】:

    这些配置是 Spring Boot 特定的,Spring Data Elasticsearch 不使用它们。但据我所知,您正在配置传输客户端(集群条目,无论如何都不应该使用)和 imperative REST 客户端,但根据错误消息,您正在使用 反应式 REST 客户端。

    根据Spring Boot documentation,您需要设置spring.data.elasticsearch.client.reactive.endpoints

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 2015-07-20
      相关资源
      最近更新 更多