The following topics describe the principles, version compatibility, and usage examples of Java REST Client of Elasticsearch. You can use Java REST Client to interact with Alibaba Cloud Elasticsearch and perform retrieval and analysis tasks.
Migrate existing code from Transport Client to Java REST Client
Transport Client is a special client that was developed with the first version of Elasticsearch. It uses TCP to communicate with Elasticsearch, which causes incompatibilities when Transport Client communicates with Elasticsearch that does not match its version. For more information, see Motivations around a new Java client.
Java Low Level REST Client was released on the open-source Elasticsearch website in 2016. Java Low Level REST Client is based on the Apache HTTP client and allows communication with an Elasticsearch cluster of all versions over HTTP. Elasticsearch has released High Level REST Client based on Low Level REST Client.
- If you want to use Transport Client to access an Alibaba Cloud Elasticsearch cluster through port 9300, purchase a cluster of V5.5 or V5.6. For Alibaba Cloud Elasticsearch V6.X or later, you cannot use Transport Client to access your Elasticsearch cluster through port 9300.
- When you use Transport Client 5.5 or 5.6 to access an Elasticsearch cluster, the NoNodeAvailableException
error message is displayed. We recommend that you use Transport Client 5.3.3 or Java Low Level REST Client to access the Elasticsearch cluster to ensure compatibility. If Transport Client
is used, set
client.transport.sniffto false. For more information, see Transport Client (5.x).
Java REST Client
- Java Low Level REST Client: Java Low Level REST Client communicates with an Elasticsearch cluster over HTTP. APIs are not responsible for data encoding and decoding. Java Low Level REST Client is compatible with Elasticsearch of all versions.
- Java High Level REST Client: This type of client is used as an example. Java High
Level REST Client is based on Java Low Level REST Client. It is designed to expose
API-specific methods. Java High Level REST Client depends on the Elasticsearch core
project. The client accepts a request object as a parameter and returns a response object. All APIs can be synchronously or asynchronously called.
- The synchronous methods return a response object.
- The asynchronous methods, whose names are suffixed with the async, require a listener parameter. The listener parameter notifies the target method to proceed when a response or error is received.
For more information about how to use Elasticsearch, click here.