1、导入相关的依赖
org.elasticsearch.client
elasticsearch-rest-high-level-client
6.3.2
2、配置文件
spring: data: #ElasticSearch的连接地址 elasticsearch: cluster-name: elasticsearch cluster-nodes: localhost:9300
3、创建实体类
@Data
@document(indexName = "shop", type = "user", refreshInterval = "0s")
public class User {
@Id
private Long id;
@Field(type = FieldType.Keyword)
private String username;
@Field(type = FieldType.Text)
private String realname;
private String password;
private Integer age;
}
4、写一个类继承ElasticsearchRepository
public interface UserRepository extends ElasticsearchRepository{ }
5、然后就可以在controller里面调用api实现基本的增删改查了。



