Transport Client
editTransport Client
editThe TransportClient
connects remotely to an Elasticsearch cluster
using the transport module. It does not join the cluster, but simply
gets one or more initial transport addresses and communicates with them
in round robin fashion on each action (though most actions will probably
be "two hop" operations).
// on startup Client client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300)) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300)); // on shutdown client.close();
Note that you have to set the cluster name if you use one different than "elasticsearch":
Settings settings = Settings.settingsBuilder() .put("cluster.name", "myClusterName").build(); Client client = TransportClient.builder().settings(settings).build(); //Add transport addresses and do something with the client...
Or using elasticsearch.yml
file as shown in Node Client
The client allows sniffing the rest of the cluster, which adds data nodes
into its list of machines to use. In this case, note that the IP addresses
used will be the ones that the other nodes were started with (the
"publish" address). In order to enable it, set the
client.transport.sniff
to true
:
Settings settings = Settings.settingsBuilder() .put("client.transport.sniff", true).build(); TransportClient client = TransportClient.builder().settings(settings).build();
Other transport client level settings include:
Parameter | Description |
---|---|
|
Set to |
|
The time to wait for a ping response
from a node. Defaults to |
|
How often to sample / ping
the nodes listed and connected. Defaults to |