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

被折叠的 条评论
为什么被折叠?



