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) {
     }
   }
 }
相关推荐
QiLinkOS32 分钟前
行业规则的“强制升级”:从“数量竞赛”到“质量博弈”
大数据·人工智能·产业链坐标定位·矩规双螺旋归因模型·矩规评级·科创技术评级·技术坐标刻度模型
风翼靓崽2 小时前
ES综合日志平台搭建
大数据·elasticsearch·搜索引擎
TDengine (老段)2 小时前
TDengine IDMP ---- Excel 插件
大数据·数据库·excel·时序数据库·tdengine·涛思数据
大大大大晴天12 小时前
Agent 的“手和脚”:工具接口如何做到安全、可靠与可治理
大数据
XW96325814 小时前
除湿机行业组织能力与人才地图报告
大数据·服务器·网络·数据结构·数据库·人工智能
大大大大晴天20 小时前
每天认识一个组件:ZooKeeper
大数据
Java展博21 小时前
[工程化基本功] 合并两条分支时,merge 和 rebase 到底改了谁的历史
大数据·elasticsearch·搜索引擎
Lansonli1 天前
大数据Spark(九十五):Spark Shuffle 参数调优全解析
大数据·分布式·spark
老周聊架构1 天前
从智能应用到智能组织:一场架构级的范式跃迁
大数据·人工智能·架构
Nefu_lyh2 天前
【Spark】05Spark 数据读取与保存:文件格式、文件系统与结构化数据
大数据·分布式·spark