SpringBoot整合ES(REST Client方式)并实现简单的增删改查

本文介绍了在SpringBoot中使用REST Client方式集成Elasticsearch,并实现基本的增删改查操作。由于Java API即将被弃用,作者推荐使用REST Client。文章详细阐述了配置依赖、YML设置,以及在Service和Controller层如何编写代码来完成各种操作。同时指出,对于更复杂的查询需求,需要进一步学习使用Rest-High-Level-Client。
摘要由CSDN通过智能技术生成

首先有三种方式可以实现在java代码里操作ES,分别是Java API(TransportClient客户端),REST Client以及Data-ES,对于第一种,ES官方表示将在ES 8.0版本弃用,所以不是我们学习的重点。至于Data-ES,虽然它和SpringBoot集成的很好,容易上手,而且提供了很方便的api,但是据说不支持ES的权限数据,如果只是很简单的获取普通数据,Data-ES将是很好的一个方式。但如果需要获取权限数据呢?

集成准备工作

首先pom依赖如下

    <dependencies>
        <!-- springboot相关 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--yml文件进行配置需要用到的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- elasticsearch -->
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.8.4</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>6.8.4</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.plugin</groupId>
            <artifactId>reindex-client</artifactId>
            <version>6.8.4</version>
        </dependency>
        <!-- 工具包 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.54</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值