导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
配置文件配置ES
spring:
application:
name: hrm-es-service
data:
elasticsearch:
cluster-name: elasticsearch
cluster-nodes: 127.0.0.1:9300 #9200是图形界面端,9300代码端
创建EmployeeDoc
/**
* 针对于 Employee 表的文档映射
* indexName:索引库
* type:类型(表类型)
*/
@Document(indexName = "hrm" , type = "employee")
public class EmployeeDoc {
//对应文档的id
@Id
private Long id;
@Field(type = FieldType.Keyword) //指定为 不分词
private String userName;
private int age;
@Field(type =FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
private String intr;
...
创建索引库
@RunWith(SpringRunner.