Elasticsearch简便使用

1.引入依赖

2.启动类上添加注解 

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

因为已经配置过mysql数据源,所以要取消自动装配的数据源

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//取消数据源自动配置
@EnableDiscoveryClient
@EnableFeignClients
/**
 * 启动类
 */
public class ServiceSearchApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceSearchApplication.class, args);
    }

}

3.创建Es对应实体类

 


@Data
@Document(indexName = "skues" ,shards = 3,replicas = 1)
public class SkuEs {

    // 商品Id= skuId
    @Id
    private Long id;

    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String keyword;

    @Field(type = FieldType.Integer, index = false)
    private Integer skuType;

    @Field(type = FieldType.Integer, index = false)
    private Integer isNewPerson;

    @Field(type = FieldType.Long)
    private Long categoryId;

    @Field(type = FieldType.Text)
    private String categoryName;

    @Field(type = FieldType.Keyword, index = false)
    private String imgUrl;

    //  es 中能分词的字段,这个字段数据类型必须是 text!keyword 不分词!
    @Field(type = FieldType.Text)
    private String title;

    @Field(type = FieldType.Double)
    private Double price;

    @Field(type = FieldType.Integer, index = false)
    private Integer stock;

    @Field(type = FieldType.Integer, index = false)
    private Integer perLimit;

    @Field(type = FieldType.Integer, index = false)
    private Integer sale;

    @Field(type = FieldType.Long)
    private Long wareId;

    //  商品的热度!
    @Field(type = FieldType.Long)
    private Long hotScore = 0L;

    @Field(type = FieldType.Object, index = false)
    private List<String> ruleList;

4.创建Repository接口(继承ElasticsearchRepository)

public interface XxxRepository extends ElasticsearchRepository<SkuEs,Long> {
}

5.调用XxxRepository的方法

//此处只是简单举例
//直接 接口.可以调用操作es的方法
xxxRepository.save(skuEs);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值