【ElasticSearch(十三)进阶】SpringBoot整合ElasticSearch7.14.0 基本教程

【ElasticSearch(十三)进阶】SpringBoot整合ElasticSearch7.14.0 基本教程

一、接入方式

1.端口9300:TCP

1)spring-data-elasticsearch:transport-api.jar:

springboot版本不同,transport-api.jar 不同,不能适配es版本

7.x 已经不建议使用,8以后就要废弃

2.端口9200:HTTP

1)JestClient

非官方,更新慢

2)RestTemplate

模拟发HTTP请求,ES很多操作需要自己封装,麻烦

3)HttpClient

同上

4)Elasticsearch-Rest-Client(我们选择的)

官方RestClient,封装了ES操作,API层次分明,上手简单

(使用指南)

https://www.elastic.co/guide/en/elasticsearch/client/index.html

二、搭建项目

我使用的版本是ElasticSearch 7.14,配合SpringBoot搭建项目。

三、导入Maven

由于父依赖spring-boot-dependencies导入的elasticsearch依赖版本是7.12.1的,所以这里我们另外在<properties>标签下定义下elasticsearch版本是7.14的。

<properties>
    <java.version>1.8</java.version>
    <elasticsearch.version>7.14.0</elasticsearch.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>

    <!-- 导入es的rest-high-level-client和elasticsearch server-->
    <dependency>
        <groupId>org.elasticsearch.clie
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot中集成Elasticsearch时,需要进行mapping配置。根据引用\[2\]中的代码示例,可以创建一个名为EsGoodsRepository的接口,并继承ElasticsearchRepository。在该接口中,可以定义对应的实体类和主键类型。这样就可以通过该接口来进行Elasticsearch的操作了。 另外,根据引用\[1\]中的说明,为了允许外部访问Elasticsearch,需要修改配置文件。配置文件的路径在config/elasticsearch.yml。可以使用vi命令打开该文件进行修改。 总结起来,集成Elasticsearch时,需要创建EsGoodsRepository接口,并继承ElasticsearchRepository,同时进行mapping配置。另外,还需要修改Elasticsearch的配置文件以允许外部访问。 #### 引用[.reference_title] - *1* *3* [SpringBoot集成Elasticsearch7.4 实战(一)](https://blog.csdn.net/qq_37284798/article/details/128718272)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [SpringBoot集成elasticsearch使用(增删改查)](https://blog.csdn.net/ljfgyy0205/article/details/130086495)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值