ElasticSearch 不支持的主鍵數據類型

前言

     前段時間遇到ES 中數據類型的一個坑,ElasticsearchRepository<T,ID>中的ID不支持BigInteger 類型, 說一下入坑的過程。

正文

使用BigInteger 報錯

1、定義Entity

@Data
@Builder
@Document(indexName = "paper", type = "index", shards = 5, replicas = 1, refreshInterval = "-1")
public class PaperIndex {
    @Id
    private BigInteger id;

    /**
     * 標題
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String title;

    /**
     * 摘要
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String summary;

2、 定義Repository

@Component
public interface PaperIndexRepository extends ElasticsearchRepository<PaperIndex, BigInteger> {
}

3、啓動程序的錯誤日誌

# 參數異常:不支持BigInteger 類型
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Unsupported ID type class java.math.BigInteger

查看源碼

實現類:
在這裏插入圖片描述
未完待續。。

總結

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章