添加依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
配置
#集群名称
spring.data.elasticsearch.cluster-name=elasticsearch
#es 的地址和端口
spring.data.elasticsearch.cluster-nodes=192.168.7.188:9300
实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
//配置 indexName 索引名称,type 是类型名称,shards 是分片数,replicas 是副本数
@Document(indexName = "goods",type = "_doc",shards = 1,replicas = 0)
public class Goods {
@Id
private Long id;
//配置字段,type 是类型,analyzer 是分词器,index 是否索引
@Field(type = FieldType.Text,analyzer = "ik_max_word")
private String name;
@Field(type = FieldType.Keyword)
</