spring-boot-starter-data-elasticsearch 版本踩坑,巨坑!(各种连接异常)

		<!--引入elasticsearch-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
		</dependency>

接入后,项目总是跑不起来

我的报错部分内容:

Exception in thread "I/O dispatcher 1" java.lang.AssertionError

CloseableHttpAsyncClientBase$1 66 run - I/O reactor terminated abnormally org.apache.http.nio.reactor.IOReactorException: I/O dispatch worker terminated abnormally

2021-09-01 19:04:34.758 ERROR org.springframework.boot.SpringApplication 826 reportFailure - Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is org.springframework.data.elasticsearch.ElasticsearchException: Error while for indexExists request: org.elasticsearch.action.admin.indices.get.GetIndexRequest@2416378c

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is org.springframework.data.elasticsearch.ElasticsearchException: Error while for indexExists request: org.elasticsearch.action.admin.indices.get.GetIndexRequest@2416378c
 

首先,maven会根据你的springboot版本自动为你匹配对应的版本spring-boot-starter-data-elasticsearch,比如我的springboot版本是2.2.13.RELEASE,spring-boot-starter-data-elasticsearch的匹配的版本是3.2.12.RELEASE。

 

经过一番折腾,发现Spring Data Elasticsearch 、Elasticsearch服务器、Spring Boot这三个版本号必须要一致才行,不然会有各种报错!!!

具体情况官网:Spring Data Elasticsearch - Reference Documentation

application.properties文件

#elasticsearch
spring.elasticsearch.rest.uris=192.168.11.6:9200

解决:

下载自己项目对应的elasticsearch版本重新安装即可,官网下载地址如下(地址的“6-8-12”是版本号可以改成自己项目对应的版本来下载):

Elasticsearch 6.8.12 | Elastic

另外,如果需要下载官方elasticsearch的可视化客户端工具kibana的话,也是需要版本和elasticsearch一致才行。我这里的elasticsearch是6-8-12,则kibana也需要是6-8-12版本的,不然会出行兼容问题。

https://www.elastic.co/cn/downloads/past-releases/kibana-6-8-12

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐