This topic describes how to use Transport Client 5.3.3 to access a cluster of Alibaba Cloud Elasticsearch V5.X.


We recommend that you use Transport Client 5.3.3 to access an Elasticsearch cluster. If you use Transport Client 5.5 or 5.6 to assess an Elasticsearch cluster, the error message "NoNodeAvailableException" is displayed.

Java Transport Client communicates with Elaticsearch over TCP. If the client communicates with different versions of Elasticsearch, incompatibilities may occur. In the later versions of open-source Elasticsearch, Transport Client is deprecated. We recommended that you use Java Low Level REST Client to access the Elasticsearch cluster to ensure compatibility.

This topic only provides sample code. For more information, see Call the document API.


  • Install a JDK. The JDK version must be 1.8 or later.

    For more information, see Install the JDK.

  • Create a cluster of Alibaba Cloud Elasticsearch V5.5.

    For more information, see Create an Elasticsearch cluster.

  • Enable the Auto Indexing feature for the Elasticsearch cluster.

    For more information, see Enable auto indexing.

    If the Auto Indexing feature is not enabled, the following error message is displayed.Error
  • Enable the public endpoint of your Elasticsearch cluster and add the public IP address of your host to the public whitelist.

    For more information, see Configure a whitelist to access an Elasticsearch cluster over the Internet or a VPC.

    Note If you want to query the public IP address of your host, open Google Chrome, enter IP, and click What Is My IP Address. You can obtain the public IP address of your host on the web page that appears.
  • Create a Java Maven project and add the Project Object Model (POM) dependencies to the pom.xml file of the Java project. For more information, see POM dependencies.

POM dependencies




import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;

import static org.elasticsearch.common.xcontent.XContentFactory.*;


public class TransportClientDemo {

    public static void main(String[] args) {
        try {
            TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
                    .put("", "es-cn-mpddddddt5l") //Set the value to the ID of the target Elasticsearch cluster.
                    .put("", "elastic:123456") //Set the value to the username and password for accessing the target Elasticsearch cluster.
                    . put("client.transport.sniff", false) //set the value to false.
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(""), 9300));
                     //Specify the endpoint and port.
            //You can modify the following code as required, for example, you can change the values of the index, type, and document ID.
            IndexResponse idxResp3 = client.prepareIndex("test_index", "test_type", "333")
                            .field("user_id", "333")
                            .field("email", "")


            GetResponse getResp =

        } catch (Exception e) {
Parameter Description Set the value to the ID of the Elasticsearch cluster.
client.transport.sniff Set the value to false. Set the value to the username and password for accessing the Elasticsearch cluster.
InetAddress.getByName() Specify the endpoint and port number of the Elasticsearch cluster that you want to access.
Notice The endpoint cannot start with http.