我試圖使用遠程彈性搜索集群運行一個測驗代碼。 我所擁有的唯一配置是遠程 ES 集群地址。
但是我的代碼突然尋找localhost:9200 ES集群。
你們誰知道發生了什么?
測驗結果的記錄
1. 證明了遠程ES集群的連接(也許?202109-09 23:48:18. 302 DEBUG 52659 --- [Test worker] org.elasticsearch.client.RestClient : request [GET http://{my-remote-elasticsearch-host}:{port}/] returned [HTTP/1.1 200 OK]/span>
2021-09-09 23:48:18. 336 INFO 52659 -- [Test worker] o.s.d.elasticsearch.support.VersionInfo : Version Spring Data Elasticsearch: 4.2.3。
2021-09-09 23:48:18. 337 INFO 52659 -- [Test worker] o.s.d.elasticsearch.support.VersionInfo : Version Elasticsearch Client in build: 7.12.1.
2021-09-09 23:48:18. 337 INFO 52659 -- [Test worker] o.s.d.elasticsearch.support.VersionInfo : Version Elasticsearch Client used: 7.12.1.
2021-09-09 23:48:18. 337 INFO 52659 -- [Test worker] o.s.d.elasticsearch.support.VersionInfo : Version Elasticsearch cluster: 7.10.1.
2021-09-09 23:48:18. 337 WARN 52659 --- [Test worker] o.s.d.elasticsearch.support.VersionInfo : Elasticsearch Client 和 Cluster 之間存在版本不匹配。7.12.1 - 7.10.1
2.對localhost:9200
的未預期的嘗試
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.elasticsearch.client.NoReachableHostException: 主機'localhost:9200'無法到達。集群狀態為脫機。
原因是:org.springframework.data.elasticsearch.client.NoReachableHostException。主機'localhost:9200'無法到達。集群狀態為脫機。
at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider.lambda$lookupActiveHost$3(SingleNodeHostProvider.java:101)
at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider$$Lambda$1993/0x000000000000.accept(未知來源)。
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:103)
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220)
代碼
Bean
@Bean
public RestHighLevelClient elasticsearchClient(){
String hostAndPort = new HttpHost(getElasticsearchProperty()。 getConnectionProperty().getHosts(), Integer.parseInt(getElasticsearchProperty().getConnectionProperty().getPorts())).toHostString()。
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(hostAndPort)
.build()。
return RestClients.create(clientConfiguration).rest()。
配置 yml
- filename: elasticsearch-local.yml
elasticsearch:
內容:
connectionProperty:
hosts: {remote-es-host}。
ports:/span> {remote-port}
connectionTimeout: 3000
socketTimeout: 5000
user: {user}
password: {password}。
專案結構
- 以Gradle為基礎
? project
? project-api
?專案-elasticsearch
project-api
- 依賴于
project-elasticsearch。
- 現在我試圖在這個專案中運行測驗代碼。
project-elasticsearch
- 所有與Elasticsearch相關的配置或實用程式 。
- 我嘗試在這個專案中運行測驗代碼,并成功連接到遠程ES集群。
uj5u.com熱心網友回復:
你沒有提供Elasticsearch的配置代碼,根據你的假設,它應該指的是正確的主機。無論如何,我相信這些鏈接將解釋你需要知道的所有配置(我假設localhost是默認的,因為你沒有根據需要進行配置).
uj5u.com熱心網友回復:
我解決了我的問題,在project-api中添加了以下內容。
spring:
autoconfigure:
exclude: >
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchReactiveHealthContributorAutoConfiguration。
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration。
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration
問題是,Spring的自動配置試圖使用ReactiveElasticsearchRestClient,但沒有為反應式的配置。因此,它自動嘗試連接到localhost.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/315191.html
標籤:
