This topic describes the principles, version compatibility, and usage examples of Java clients for Elasticsearch. You can use a Java client to interact with Elasticsearch and perform retrieval and analytics tasks.
Migrate existing code from Transport Client to a REST client
Transport Client is a special client that was developed with the first version of Elasticsearch. It communicates with Elasticsearch over TCP. If it communicates with Elasticsearch of a version that does not match its version, incompatibility issues may occur. For more information, see Motivations around a new Java client.
Elasticsearch released Java Low Level REST Client in 2016. Java Low Level REST Client is developed based on the Apache HTTP client and can communication with all versions of Elasticsearch clusters over HTTP. Elasticsearch also released High Level REST Client based on Low Level REST Client.
- You can use Transport Client to access only Alibaba Cloud Elasticsearch V5.5 or V5.6 clusters over port 9300. Alibaba Cloud Elasticsearch clusters of V6.X or later does not support Transport Client.
- If you use Transport Client 5.5 or 5.6 to access an Alibaba Cloud Elasticsearch cluster,
the system displays the "NoNodeAvailableException" error message. To ensure version
compatibility, we recommend that you use Transport Client 5.3.3 or Java Low Level REST Client to access an Elasticsearch cluster. If Transport Client is used, set
client.transport.sniffto false. For more information, see Transport Client (5.x).
Java REST clients
- Java Low Level REST Client: communicates with an Elasticsearch cluster over HTTP. API operations do not encode or decode data. Java Low Level REST Client is compatible with all versions of Elasticsearch.
- Java High Level REST Client: Java High Level REST Client is developed based on Java
Low Level REST Client and is designed to expose API operation-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 API operations
can be synchronously or asynchronously called.
- The synchronous method returns a response object.
- The asynchronous method, whose name is suffixed with async, requires a listener parameter. This parameter notifies the target method to proceed when a response or error is received.