Spring Boot整合Spring Data Elasticsearch 踩坑

时间:2024-05-20 08:12:16

首先来看官网给的版本要求:

Spring Boot整合Spring Data Elasticsearch 踩坑

红框这栏指的是:Elasticsearch安装版本(windows安装版本或Linux按照版本)

最新因为项目需要elasticsearch,采用今天搞了好久,项目启动就报如下错误:

org.elasticsearch.transport.NodeDisconnectedException: [][127.0.0.1:9300][cluster:monitor/nodes/liveness] disconnected

找了好久以为是配置问题,最后终于明白原来是版本不统一。

我的项目用的spring boot 1.5.x

所以安装了elasticsearch-2.3.2.zip

解压进入bin目录双击elasticsearch.bat。启动服务。

在浏览器输入http://localhost:9200/,返回json字符串证明启动成功。

Spring Boot整合Spring Data Elasticsearch 踩坑

###################################################################

在springboot中对elasticsearch配置是默认有支持的。

Spring Boot整合Spring Data Elasticsearch 踩坑

Spring Boot整合Spring Data Elasticsearch 踩坑

如配置:

 

#默认 9300 是 Java 客户端的端口。9200 是支持 Restful HTTP 的接口。
#  集群节点地址列表,用逗号分隔。如果没有指定,就启动一个客户端节点
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.repositories.enabled=true

以前就绪,操作就类似于Spring-Data-JPA,具体见官方文档http://projects.spring.io/spring-data-elasticsearch/

安装Head插件
E:\soft\elasticsearch-2.3.2\bin>plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
ERROR: failed to download out of all possible locations..., use --verbose to get
 detailed information

E:\soft\elasticsearch-2.3.2\bin>plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading ....................................................................
....................................终止批处理操作吗(Y/N)? y

E:\soft\elasticsearch-2.3.2\bin>plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading ....................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksum
s if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .
md5 file to verify)
Installed head into E:\soft\elasticsearch-2.3.2\plugins\head

以上完成启动es.

访问http://localhost:9200/_plugin/head/

Spring Boot整合Spring Data Elasticsearch 踩坑

                                           Spring Boot整合Spring Data Elasticsearch 踩坑

                                                                       JAVA程序猿成长之路

                                                    分享学习资源,学习方法,记录程序员生活。