使用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

翻譯: 不能更改現有的映射類型,需要使用正確的映射創建新的索引,然后重新索引數據。

需要怎么做呢?

刪除有問題的索引,為每個屬性指定相應的類型。重新索引數據。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM