栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

SpringData JPA集成ElasticSearch及其使用

SpringData JPA集成ElasticSearch及其使用

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实现基本的增删改查了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/663324.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号