美文网首页
Spring Boot集成ElasticSearch

Spring Boot集成ElasticSearch

作者: 云师兄 | 来源:发表于2018-07-10 08:24 被阅读97次

添加maven依赖

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

补充配置文件

在application.properties配置文件中填写:

spring.data.elasticsearch.properties.transport.tcp.connect_timeout=120s
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300
  • 注意本地java端口默认为9300,而不是9200

ElasticSearch安装

之前一直连接失败的原因是spring boot ,spring data,elasticsearch三者的版本不匹配,具体的匹配如下:


屏幕快照 2018-07-10 上午8.20.05.png

由于当前spring boot的版本为1.5.1,所以就只支持elasticsearch版本为2.0.0到5.0.0的部分,如果像之前选了6点几的版本就会出现连接失败等其他问题,换了低版本的2.4.1后就能正常使用了。

上述三步都完成后就可以在spring boot中进行es的相关操作了。

相关文章

网友评论

      本文标题:Spring Boot集成ElasticSearch

      本文链接:https://www.haomeiwen.com/subject/cqnxpftx.html