前言
前段時間遇到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
查看源碼
實現類:
未完待續。。