Elasticsearch-Elasticsearch-Rest-Client(三)

1)TCP

spring-data-elasticsearch:transport-api.jar;

springboot版本不同,transport-api.jar不同,不能适配es版本, 7.x已经不建议使用,8以后就要废弃

2)、9200:HTTP

JestClient:非官方,更新慢

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

HttpClient:同上

Elasticsearch-Rest-Client:官方RestClient,封装了ES操作,API层次分明,上手简单

最终选择Elasticsearch-Rest-Client(elasticsearch-rest-high-level-client) https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html

1、SpringBoot整合

复制代码
<dependency>
     <groupId>org.elasticsearch.client</groupId>
     <artifactId>elasticsearch-rest-high-level-client</artifactId>
     <version>7.4.2</version>
 </dependency>

2、配置

复制代码
@Bean RestHighLevelClientclient(){ 
    RestClientBuilder builder = RestClient.builder(newHttpHost("192.168.56.10", 9200, "http")); 
    return new RestHighLevelClient(builder); 
}

3、使用 参照官方文档

复制代码
@Test
 void test1() throwsIOException{
     Product product=new Product();
     product.setSpuName("华为");
     product.setId(10L);
     IndexRequest request=new IndexRequest("product").id("20").source("spuName","华为","id",20L);
try{
     IndexResponse response=client.index(request,RequestOptions.DEFAULT);
     System.out.println(request.toString());
    IndexResponse response2 = client.index(request, RequestOptions.DEFAULT);
 } catch (ElasticsearchException e) {
     if (e.status() == RestStatus.CONFLICT) {
     }
   }
 }
相关推荐
大模型探索者5 小时前
2026 企业智能体平台选型指南:从通用到行业深耕,怎么选?
大数据·人工智能
阿三081210 小时前
跨境电商售后自动化分级标准:哪些能全自动、哪些半自动、哪些禁止自动化
大数据·人工智能·自动化
游戏新手村11 小时前
蝴蝶图在餐饮门店数据可视化中的应用
大数据·信息可视化·产品经理·数据可视化
GlobalHRTalk12 小时前
埃及名义雇主EOR业务概述与市场发展优势分析
大数据·运维·人工智能
码云数智-园园14 小时前
Hyperf 协程 PHP 实战:传统 PHP 如何实现高并发服务
大数据
找方案14 小时前
北京砸1亿支持智能体:Agent创业迎来黄金窗口期
大数据·人工智能·microsoft
Elasticsearch14 小时前
你的 SLO 已经告急;下面介绍如何在 Elastic Observability 中找出罪魁祸首
elasticsearch
Black蜡笔小新14 小时前
EasyAIS+国标GB28181视频监控平台EasyCVR强强联动,全域视频AI识别能力落地!
大数据·人工智能·音视频
瓦学妹15 小时前
X(Twitter)新号如何防封?2026 养号与防限流全攻略
大数据·网络·人工智能·新媒体运营·twitter
EAIReport15 小时前
企业GEO全域运营技术落地路线与量化效果验证方案(AI大数据行业适配)
大数据·人工智能