本篇是这个系列的最后一篇了,在这之前可以先看看前面的内容:
ES搜索引擎入门+最佳实践(一)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(二)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(三)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(四)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(五)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(六)_flame.liu的博客-CSDN博客
ES搜索引擎入门+最佳实践(七):聚合_flame.liu的博客-CSDN博客
这篇文章将介绍使用ES JAVA API对ES中的数据进行增删改查.
一.添加引用
ES高级客户端已经被放弃,所以这里使用的是elasticsearch-java
<!-- es java客户端-->
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
</dependency>
<!-- jsom与java对象之间的转换-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
二. 创建ES客户端的配置类
package com.flamelp.productessearch.config;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ESClientConfig {
// @Value("${elasticsear