Elastic Search 8.6.2客户端实战

本文详细介绍了如何使用Java与Elasticsearch 8.6.2进行交互,重点讲解了通过Spring Boot客户端和RestClient的方式。对于Spring Boot,展示了如何配置连接属性,利用Spring Data Elasticsearch实现Repository接口,进行自动化的查询和数据映射。而对于RestClient,介绍了创建项目、配置和基本使用步骤。
摘要由CSDN通过智能技术生成

Elastic Search 8.6.2客户端实战

Elastic Search和客户端交互,可以使用很多语言来完成搜索,如:Java、Python、Php和Go等多种语言。由于我平常使用最多的就是Java,这里仅基本于Java语言来演示。基于Java语言可以选择的客户端包括RestClient、Spring Data Elasticsearch。安装的话可以参考《Elastic Search 8.6.2集群安装部署》。

4.1使用RestClient【简单介绍】

参考文档:

https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/introduction.html

创建项目Spring Boot Web项目 es-demo,配置项目pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 " target="_blank">https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>2.5.0</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<groupId>com.study</groupId>

<artifactId>es-demo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>es-demo</name>

<description>Elastic Search Demo project for Spring Boot</description>

<properties>

<java.version>17</java.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>org.elasticsearch.client</groupId>

<artifactId>elasticsearch-rest-client</artifactId>

<version>8.6.2</version>

</dependency>

<dependency>

<groupId>co.elastic.clients</groupId>

<artifactId>elasticsearch-java</artifactId>

<version>8.6.2</version>

</dependency>

<dependency>

<groupId>org.elasticsearch</groupId>

<artifactId>elasticsearch</artifactId>

<version>8.6.2</version>

</dependency>

<dependency>

<groupId>org.projectlombok</groupId>

<artifactId>lombok</artifactId>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悦睹人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值