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 = new TransportClient() .addTransportAddress(new InetSocketTransportAddress("host1", 9300)) .addTransportAddress(new InetSocketTransportAddress("host2", 9300)); // on shutdown client.close();
Note that you have to set the cluster name if you use one different than "elasticsearch":
Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", "myClusterName").build(); Client client = new TransportClient(settings); //Add transport addresses and do something with the client...
Or using elasticsearch.yml
file as shown in the Node
Client section
The client allows to sniff the rest of the cluster, and add those 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 = ImmutableSettings.settingsBuilder() .put("client.transport.sniff", true).build(); TransportClient client = new TransportClient(settings);
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 |