使用elasticsearch启动项目报错failed to load elasticsearch nodes 。。。。。No type specified for field [name]

failed to load elasticsearch nodes 。。。。。No type specified for field [name]
翻译: 加载ElasticSearch节点失败。。。。。没有为字段[名称]指定类型

所使用elasticsearch版本为5.6.15

原因一:

如果是使用java类来映射elasticsearch中index下的type

那么当使用@Field注解时,请指定属性的类型

// 引入的包
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

// 像这样
@Field(type = FieldType.Long)
private Long id;
    
// 不可这样, 启动项目时由于不知道属性的类型,所以无法创建index下的type
@Field
private Long id;

但是在做新增操作时,elasticsearch会自动创建类型, 而这个类型下的属性下的参数是有问题的(也可能是我看不懂)

如下图部门名称是自动生成的

 其实我们只需要指定部门的类型即可,像这样

@Field(type = FieldType.Text)
private String departmentName;

我们不需要fields这个属性

注意每当我们改变elasticsearch中的index下的type下的属性名的类型或参数时,就我所知只能删除index重新生成(我不知道如何删除index下的type)

 否则便会报如下错

You can't change existing mapping type, you need to create a new index with the correct mapping and index the data again

翻译: 不能更改现有的映射类型,需要使用正确的映射创建新的索引,然后重新索引数据。

需要怎么做呢?

删除有问题的索引,为每个属性指定相应的类型。重新索引数据。

猜你喜欢

转载自www.cnblogs.com/sjj162/p/11130504.html