Elasticsearch Java 客户端的选择

Elasticsearch 提供了三种Java API接口:
Java client:
这是TransportClient 提供的原生客户端,不能执行原生DSL语句必须使用它的Java API方法。

注意:
在Elasticsearch 7 版本中Elasticsearch官方宣布计划在7.0版本TransportClient被标记为Deprecated,将在
8.0版本删除。

REST API:
这种客户端可以使用DSL语句拼接字符串直接传递给服务端 然后返回json字符进行解析。
Rest API有提供了2种分别为低阶(low level)和高阶(High Level)
低阶的API获取的信息较少,高阶的API直接的功能较多。

结论:
在实际生产开发中优先选择使用REST API的High-level API。



Java REST API:
The Java REST Client comes in 2 flavors:

Java Low Level REST Client: the official low-level client for Elasticsearch. It allows to communicate 
with an Elasticsearch cluster through http. Leaves requests marshalling and responses un-marshalling 
to users. It is compatible with all Elasticsearch versions.

The low-level client’s features include:

minimal dependencies
load balancing across all available nodes
failover in case of node failures and upon specific response codes
failed connection penalization (whether a failed node is retried depends on how many consecutive 
times it failed; the more failed attempts the longer the client will wait before trying that same
 node again)
persistent connections
trace logging of requests and responses
optional automatic discovery of cluster nodes

Maven中使用的:

    org.elasticsearch.client
    elasticsearch-rest-client
    7.5.1


    org.elasticsearch.client
    elasticsearch-rest-client-sniffer
    7.5.1



Gradle中使用:
dependencies {
    compile 'org.elasticsearch.client:elasticsearch-rest-client:7.5.1'
}
dependencies {
    compile 'org.elasticsearch.client:elasticsearch-rest-client-sniffer:7.5.1'
}


低阶:
The low-level Java REST client internally uses the Apache Http Async Client to send http requests. 
It depends on the following artifacts, namely the async http client and its own transitive dependencies:

org.apache.httpcomponents:httpasyncclient
org.apache.httpcomponents:httpcore-nio
org.apache.httpcomponents:httpclient
org.apache.httpcomponents:httpcore
commons-codec:commons-codec
commons-logging:commons-logging



Java High Level REST Client: the official high-level client for Elasticsearch. Based on the low-level 
client, it exposes API specific methods and takes care of requests marshalling and responses
 un-marshalling.
依赖的软件包:
The High Level Java REST Client depends on the following artifacts and their transitive dependencies:

org.elasticsearch.client:elasticsearch-rest-client
org.elasticsearch:elasticsearch



    org.elasticsearch.client
    elasticsearch-rest-high-level-client
    7.5.1


Gradle的配置:
dependencies {
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.5.1'
}

功能介绍:

Java client:


    org.elasticsearch.client
    transport
    7.5.1



    org.apache.logging.log4j
    log4j-core
    2.11.1


若使用log4j2:

    org.apache.logging.log4j
    log4j-to-slf4j
    2.11.1


    org.slf4j
    slf4j-api
    1.7.24


    org.slf4j
    slf4j-simple
    1.7.21


Java客户端的使用:
You can use the Java client in multiple ways:

Perform standard index, get, delete and search operations on an existing cluster
Perform administrative 
tasks on a running cluster
Obtaining an Elasticsearch Client is simple. The most common way to get a client is by creating a TransportClient
 that connects to a cluster.


警告:
TransportClient
Deprecated in 7.0.0.
The TransportClient is deprecated in favour of the Java High Level REST Client and will be removed in 
Elasticsearch 8.0. The migration guide describes all the steps needed to migrate.



Elasticsearch和spring boot结合使用需要导入的包:




    org.springframework.boot
    spring-boot-starter-data-elasticsearch
    2.2.2.RELEASE






    io.searchbox
    jest
    6.3.1





    net.java.dev.jna
    jna
    5.5.0



Elasticsearch 6.3 版本的选择:

   org.springframework.boot
   spring-boot-starter-data-elasticsearch




   io.searchbox
   jest
   5.3.3





   net.java.dev.jna
   jna
   4.5.1



参考:
https://www.elastic.co/guide/en/elasticsearch/client/index.html

 

你可能感兴趣的:(Elasticsearch)