Example configurationedit
// Build the settings for our transport client. Settings settings = ImmutableSettings.settingsBuilder() // Setting "transport.type" enables this module: .put("transport.type", "no.found.elasticsearch.transport.netty.FoundNettyTransportModule") // Create an api key via the console and add it here: .put("transport.found.api-key", "YOUR_API_KEY") .put("cluster.name", "YOUR_CLUSTER_ID") .put("client.transport.ignore_cluster_name", false) .put("client.transport.nodes_sampler_interval", "30s") .put("client.transport.ping_timeout", "30s") .build(); // Instantiate a TransportClient and add {n} to the list of addresses to connect to. // Only port 9343 (SSL-encrypted) is currently supported. Client client = new TransportClient(settings) .addTransportAddress(new InetSocketTransportAddress("YOUR_CLUSTER_ID-REGION.foundcluster.com", 9343));
Example usageedit
while(true) { try { System.out.print("Getting cluster health... "); System.out.flush(); ActionFuture<ClusterHealthResponse> healthFuture = client.admin().cluster().health(Requests.clusterHealthRequest()); ClusterHealthResponse healthResponse = healthFuture.get(5, TimeUnit.SECONDS); System.out.println("Got response: " + healthResponse.getStatus()); } catch(Throwable t) { System.out.println("Error: " + t); } try { Thread.sleep(3000); } catch (InterruptedException ie) { ie.printStackTrace(); } }
The JVM will cache DNS lookups infinitely, by default. Since this client is connecting to a load balancer for Elasticsearch Service which can change IP addresses, it’s important to disable this functionality. Learn more …
Complete exampleedit
A complete, runnable example can be found at https://github.com/foundit/elasticsearch-transport-module-example
Contributingedit
Report issues in the issue tracker.