SpringBoot整合ElasticSearch的連接問題
failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{4J2eCGFXSZmM3xH72WIF5A}{192.168.252.200}{192.168.252.200:9300}]
我再使用SpringBoot2.2.0,ES版本5.5時,Spring-boot-data-elasticsearch開發整合啟動出現上面的錯誤。
一開始以為是es節點名稱或者ip端口寫錯了,但是看了半天也沒有問題,瀏覽器也可以直接訪問es集群。
之后去Spring文檔中查看,發現SpringBoot對Spring-boot-data-elasticsearch的版本進行了講解
發現SpringBoot2.1.x使用的spring data es是3.1.x適配es6.x
而SpringBoot2.0.x使用3.0.x適配ES5.x
SpringBoot1.5.x就只能使用ES2.4.x的版本了
然后我把SpringBoot版本改為2.0.0之后成功啟動沒報錯,并成功訪問
可以看到,正如文檔所說,SpringBoot2.0.0使用的Spring-data-elasticsearch是3.0.5的版本,即對于es5.x的版本
正確訪問接口
springboot整合Elasticsearch6.3.2踩坑
首先確保Elasticsearch6.3.2安裝成功
1.出現NoNodeAvailableException[None of the configured nodes are available
解決:elasticsearch6.3.2的配置文件修改如下:
network.host: 192.168.3.222 #改成自己局域網ip transport.tcp.port: 9300 #springboot連接使用的端口 transport.tcp.compress: true http.port: 9100
2.not part of the cluster,節點不屬于集群問題
本人使用的是單節點
在瀏覽器輸入ip+端口
上圖中框出來的就是在springboot配置文件中cluster-name的值
3.NoSuchFieldError: LUCENE_6_0_0
本人的springboot版本是2.1.7RELEASE,在依賴中加上
<dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>7.4.0</version> </dependency>
4.Elasticsearch health check failed
解決:增加spring.elasticsearch.rest 的配置
spring: data: elasticsearch: cluster-name: docker-cluster cluster-nodes: 192.168.3.68:9300 elasticsearch: rest: uris: [http://192.168.3.68:9100]
配置好 uris 即可~
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/PAcee1/article/details/102883129