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) {
     }
   }
 }
相关推荐
Elasticsearch8 小时前
在 Google MCP Toolbox for Databases 中引入 Elasticsearch 支持
elasticsearch
Chasing Aurora8 小时前
Git 工程指引(命令+问题)
大数据·git·elasticsearch·团队开发·互联网大厂
灰鲸广告联盟8 小时前
APP广告变现定制化解决方案,助力收益提升与用户体验平衡
android·flutter·搜索引擎·ux
帅得不敢出门9 小时前
精简Android SDK(AOSP)的git项目提高git指令速度
android·java·开发语言·git·elasticsearch
TG:@yunlaoda360 云老大9 小时前
阿里云国际站代理商RPA跨境服务的适用场景有哪些?
大数据·阿里云·rpa
微盛企微增长小知识9 小时前
2025企业微信服务商测评:头部服务商微盛AI·企微管家技术实力与落地效果解析
大数据·人工智能·企业微信
TMO Group 探谋网络科技10 小时前
AI电商的应用:Magento 使用 Adobe 生成式 AI改造7大业务场景
大数据·人工智能·adobe·ai
UI设计兰亭妙微10 小时前
理性数据,温柔体验:北京兰亭妙微解码 Hydra Corps. 企业管理界面的 “松弛感设计”
大数据·人工智能·用户体验设计
慎独41310 小时前
家家有:从单向支出到价值循环,绿色积分如何 重构商业逻辑?
大数据·人工智能