AbstractElasticsearchRepository : Cannot create index: Elasticsearch exception [type=resource_alread

在springboot项目启动的时候会出现Elasticsearch仓库自动创建索引报错的的问题:

2020-12-04 09:09:28.408  WARN 25592 --- [  restartedMain] .d.e.r.s.AbstractElasticsearchRepository : Cannot create index: Elasticsearch exception [type=resource_already_exists_exception, reason=index [movie/NZ4EAyAERke10mOCVPhvrA] already exists]; nested exception is [movie/NZ4EAyAERke10mOCVPhvrA]

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

springboot版本: 2.3.0.RELEASE

此版本下的spring-data-elasticsearch模块版本为:4.0.0.RELEASE

spring-data-elasticsearch模块用到的elasticsearch版本:7.6.2

 

我在spring-data-elasticsearch项目的issue下搜到了解决方案。(仓库不应该尝试去创建一个索引当它存在时)

https://jira.spring.io/browse/DATAES-827?jql=project%20%3D%20DATAES%20AND%20text%20~%20%22already%20exists%22

4.0.1版本解决的代码提交https://github.com/spring-projects/spring-data-elasticsearch/pull/456/commits/08eef2d9e344b3ada9300d89553fc2c356a0804d

看到仓库在创建索引的时候去判断了索引存不存在也就是添加了这句代码: !indexOperations.exists()。

 

所以解决这个报错的方法就是升级你的项目版本。我是直接springboot项目从2.3.0升级到2.3.1。2.3.1版本下的spring-data-elasticsearch就是4.0.1版本了。当然了你也可以直接升级spring-data-elasticsearch的版本直4.0.1及以上。

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值