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 @ 2022-06-16 17:48  一点也不好  阅读(142)  评论(0)    收藏  举报