- 👏大家好,我是polaris_coder,很高兴认识大家!
- 🔥如果觉得我的文章对你有帮助,请一键三连支持一下!
- 📝:学习,提升自己总是没错的!
1、代码
注
:基于springboot项目。
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
application.yml
spring:
elasticsearch:
rest:
uris:
- 自己es的ip:9200
实体类User
package com.polaris.entity;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
/**
* @Author:polaris_coder
* @Version:1.0
* @Date:2024/8/13-14:54
* @Since:jdk1.8
* @Description:
*/
@Data
@Document(indexName = "user",shards = 5,replicas = 1)
public class User {
@Id
private String id;
@Field(type = FieldType.Long)
private Long uid;
@Field(type = FieldType.Text,analyzer = "ik_max_word")
private String name;
@Field(type = FieldType.Keyword)
private String addr;
}
package com.polaris;
import com.polaris.entity.User;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.