Spring Data Elasticsearch 启动报错 org.springframework.beans.factory.UnsatisfiedDependencyException 依赖不足

本文详细解析了SpringDataElasticsearch在启动时遇到的错误,具体表现为对coursedoc文档映射对象修改后服务启动失败的问题。错误核心在于不同类型的映射冲突,当前类型为text,而合并类型为keyword。文章还提供了通过ElasticsearchTemplate方法删除并重建索引的解决方案,并附带一篇SpringDataElasticsearch入门文章链接。

Spring Data Elasticsearch 启动报错 

 对文档映射对象coursedoc修改后启动服务报错

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchController': Unsatisfied dependency expressed through field 'courseElasticsearchRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'courseElasticsearchRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: mapper [name] of different type, current_type [text], merged_type [keyword]

 

创建名为“”org.springframework.beans.factory.UnsatisfiedDependencyException:searchController“”的Bean时出错:通过字段“”CourseElasticsearchRepository“”表示的依赖项不满足;嵌套异常是创建名为“”CourseElasticsearchRepository“”的Bean时出现org.springframework.beans.factory.BeanCreationException:错误:调用init方法失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]:构造函数引发的异常;嵌套异常是java.lang.IllegalArgumentException:不同类型、CURRENT_TYPE[TEXT]、MERMERED_TYPE[KEYWORD]的映射器[NAME]。“

 

然后想通过ElasticsearchTemplate 的方法来删除索引重新创建

@Test
public void testesdelindex(){
    elasticsearchTemplate.deleteIndex(CourseDoc.class);
}

报错,无法执行

最后,打开kibana

DELETE hrm   admin是我的索引名

GET _mapping 查询索引库被删除

再重新创建索引库

@Test
public void createIndex(){
    //创建索引库
    elasticsearchTemplate.createIndex(CourseDoc.class);
    //文档映射
    elasticsearchTemplate.putMapping(CourseDoc.class);
}

最后发现了一片介绍Spring Data Elasticsearch很详细的入门文章 

https://www.jianshu.com/p/930c803a4ebd

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值