赞
踩
1.引入elasticsearch相关的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
pom.xml文件中最重要的其实就是引入ES(Elasticsearch的简称后面我都这么叫),也就是spring-boot-starter-data-elasticsearch 依赖。
2.接下来就是对应的配置文件了,具体配置文件如下所示:
# elasticsearch集群名称,默认的是elasticsearch
spring.data.elasticsearch.cluster-name=my-application
#节点的地址 注意api模式下端口号是9300,千万不要写成9200
spring.data.elasticsearch.cluster-nodes=192.168.11.24:9300
#是否开启本地存储
spring.data.elasticsearch.repositories.enable=true
3.索引对应的实体类如下所示:
import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; @Document(indexName = "company",type = "employee", shards = 1,replicas = 0, refreshInterval = "-1") public class Employee { @Id private String id; @Field private String firstName; @Field private String lastName; @Field private Integer age = 0; @Field private String about; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Integer getAge() { return age; } public void setAge(Integer age) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。