Elasticsearch Java API Configuration test

Source: Internet
Author: User

elasticsearch1.x,2.x,5.x with the iteration of the version, in addition to the system upgrade, the Java API has also made a relatively large adjustment, that is, the 1.X API in 2.X and 5.X or even the future 6.X version is not common.

The version used in this example is 5.6.5

I. Add MAVEN dependencies First

        <Dependency>            <groupId>Org.elasticsearch.client</groupId>            <Artifactid>Transport</Artifactid>            <version>5.6.5</version>        </Dependency>

Two. Connection mode

Settings Settings = Settings.builder (). Put ("Cluster.name", "my-application"). Build ();  // set the cluster name New Prebuilttransportclient (Settings). addtransportaddress (new inetsockettransportaddress ( Inetaddress.getbyname ("10.10.10.5"), 9300);

The output client comes with a cluster sniffing feature that dynamically adds a new host and removes the old host, and when this feature is enabled, the transport client connects to the node in its internal node list

Sniffer open mode:
Settings Settings = Settings.builder (). Put ("Client.transport.sniff", true). Build ();
Transportclient client = new prebuilttransportclient (settings);

Other transport client settings include:
Client.transport.ignore_cluster_name: Set to True to ignore the checksum of the cluster name when the node is connected
Client.transport.ping_timeout: Set the wait time for a node to get response, default 5 Seconds
Client.transport.nodes_sampler_interval: How long does it take to get/ping list of nodes and connect, default 5 seconds

Three. View cluster information

        list<discoverynode> nodes = client.connectednodes ();          for (Discoverynode node:nodes) {            System.out.println (node.gethostaddress ());            System.out.println (Node.getname ());            System.out.println (Node.getversion ());        }

Elasticsearch Java API Configuration test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.