ES 整合spring-data-elasticsearch


新建工程,引入依赖

      <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>4.2.6</version>
        </dependency

新建实体

@Document(indexName = "index")
public class EsEntity {

    @Id
    @Field(type = FieldType.Long)
    private Long id;

    /**
     * <pre>
     * "uuid": {
     *     "type": "text",
     *     "fields": {
     *         "keyword": {
     *             "ignore_above": 256,
     *             "type": "keyword"
     *         }
     *     }
     * }
     */
    @MultiField(mainField = @Field(type = FieldType.Text),
            otherFields = {@InnerField(suffix = "keyword", 
                                       type = FieldType.Keyword, 
                                       ignoreAbove = 256)})
    private String uuid;
}

新建jpa接口层

public interface EsEntityRepository extends 
    ElasticsearchRepository<EsEntity, Long> {
}

新建实现

注意点:实体中字段属性一定要指明,不然创建数据时会出现自动获取字段数据类型!!!!!!!!

 

posted @   一点也不好  阅读(127)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示