好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

想问下,这么多客户端到底啥区别,用哪个呢?

Elasticsearch | 作者 codepub | 发布于2017年11月29日 | 阅读数:8917

<!-- https://mvnrepository.com/arti ... /rest -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>5.5.3</version>
</dependency>

<!-- https://mvnrepository.com/arti ... earch -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.3</version>
</dependency>

<!-- https://mvnrepository.com/arti ... lient -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>5.6.0</version>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.0.0</version>
</dependency>
已邀请:

quanke

赞同来自: laoyang360

建议使用elasticsearch-rest-client 这也是官方建议的方式,因为其他客户端可能不维护了,elasticsearch-rest-client灵活性更高,兼容性更好
 
可以看看这个 https://quanke.gitbooks.io/ela ... rest/ 
 

ziyou - 一个学习ELK的Java程序员

赞同来自:

我现在使用的就是rest客户端,比较实用、方便,并且上手快。
现在新发了一个高级rest客户端,但是没哟深入研究,官方说要代替Java TransportClient 客户端,要选择就在这两个客户端之间选择吧,Java TransportClient 客户端是不行了。
ES的客户端现在要走精简化路线,复杂的客户端会这是耦合性太高的客户端会被渐渐淘汰
可以看一下官方的客户端文档:https://www.elastic.co/guide/e ... .html

Robot_L

赞同来自:

这么好的问题,怎么没啥人关注,我研究了一下,总结如下:
下面是gradle依赖,示例版本为6.4.3.
api "org.elasticsearch:elasticsearch:6.4.3"
api "org.elasticsearch.client:elasticsearch-rest-client:6.4.3"
api "org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.3"

api "org.elasticsearch.client:transport:6.4.3"
api "org.springframework.boot:spring-data-elasticsearch"
1、elasticsearch:6.4.3 包含TransportClient、NodeClient等客户端,其中TransportClient对于查询dsl有以QueryBuilder接口为基础的大量面向对象封装,底层使用tcp协议连接es服务器,但这个客户端已逐渐被废弃。


“关于TransportClient,elastic计划在Elasticsearch 7.0中弃用TransportClient,并在8.0中完全删除它”。


该模块被transport:6.4.3依赖,也被早期的spring-data-elasticsearch依赖。
 
2、transport:6.4.3 里仅仅包含一个类PreBuiltTransportClient,它是TransportClient的子类,拥有自动嗅探功能,可以通过任意节点地址,或者集群名,自动搜索所有节点信息,省略初始化时的集群信息设置。也跟着它爹一起逐渐被废弃。
 
3、elasticsearch-rest-client:6.4.3,低级客户端【es官方推荐】,一个简易的http连接es服务器的客户端,对于创建索引、查询等dsl没有面向对象封装,示例:
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
// 获取id为1的文档
Request request = new Request("GET", "/some_index/1");
Response response = restClient.performRequest(request);

该模块被elasticsearch-rest-high-level-client:6.4.3依赖。
 4、elasticsearch-rest-high-level-client:6.4.3,高级客户端【es官方推荐】,依赖于低级客户端elasticsearch-rest-client和elasticsearch两个模块,使用面向对象的方式来形成dsl,和TransportClient不同的是,它是通过低级客户端的http协议和es服务器来交互。
 
5、spring-data-elasticsearch:spring封装的es,使用ElasticTemplate以及@Document、@Field等注解,在创建索引的方式上也实现了面向对象设计。而ElasticsearchCrudRepository的设计让es的增删改查像数据库一样简单。封装程度非常之高。
 在spring-data-elasticsearch 4.0之前,spring底层使用TransportClient,4.0之后升级到es7.6.2,弃用了TransportClient

版本对应关系:
SpringDataElasticsearch  Elasticsearch  SpringBoot
4.0.x                              7.6.2             2.3.x
3.2.x                              6.8.6             2.2.x
3.1.x                               6.2.2             2.1.x

要回复问题请先登录注册