How to connect to remote elasticsearch server which is UP and Started using elasticsearch java client
<p>i am using this code to connect my local elastic server</p>

<pre><code>        String url = "localhost:9200";
        String encodedUrl = URLEncoder.encode(url, "UTF-8");
        Node node = nodeBuilder().settings(
                Settings.settingsBuilder()
                        .put("http.enabled", false)
                        .put("path.home", encodedUrl)
        )
                .client(true)
                .data(false)
                .node();
        return node.client();
</code></pre>

<p>I am using this code to connect remote elastic server</p>

<pre><code>       // Transport client way


        Settings settings = Settings.settingsBuilder()
                .put("cluster.name", "Test") // remote elastic cluster name which is different in my case
                .build();
        Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("**.**.***.**"), 9259)); // my remote elastic server IP and its port 
        return client;


       // And my other way of connecting (Node Client way)is


       String url = "**.**.***.**:9259";

        String encodedUrl = URLEncoder.encode(url, "UTF-8");
        Node node = nodeBuilder().settings(
                Settings.settingsBuilder()
                        .put("http.enabled", false)
                        .put("path.home", encodedUrl)
                        .put("discovery.zen.ping.unicast.hosts", "52.74.***.**")
                        .put("cluster.name", "Test")
        )
                .client(true)
                .data(false)
                .node();
        return node.client();
</code></pre>

<p>I am able to connect my local elastic server but i am unable to connect to remote elastic server, there were always some errors coming</p>

<p>NodeNotConnectedException:</p>

<p>SendRequestTransportException</p>

<p>ReceiveTimeoutTransportException</p>

<p>NodeNotAvailableException: </p>

<p>etc...</p>

<p>Can anyone help me to figure out how to connect to remote elastic server using java, as i am developing web applications in dropwizard framework and need to get data from these elastic api servers</p>

<p>while establishing a client connection with remote ES server this thing happens</p>

<pre><code>INFO  [2016-04-13 11:23:45,826] org.elasticsearch.node: [Thunderbolt] version[2.2.0], pid[4720], build[8ff36d1/2016-01-27T13:32:39Z]
INFO  [2016-04-13 11:23:45,826] org.elasticsearch.node: [Thunderbolt] initializing ...
INFO  [2016-04-13 11:23:45,826] org.elasticsearch.plugins: [Thunderbolt] modules [], plugins [], sites []
INFO  [2016-04-13 11:23:46,039] org.elasticsearch.node: [Thunderbolt] initialized
INFO  [2016-04-13 11:23:46,039] org.elasticsearch.node: [Thunderbolt] starting ...
INFO  [2016-04-13 11:23:46,732] org.elasticsearch.transport: [Thunderbolt] publish_address {127.0.0.1:9302}, bound_addresses {127.0.0.1:9302}, {[::1]:9302}
INFO  [2016-04-13 11:23:46,732] org.elasticsearch.discovery: [Thunderbolt] Test/eZo2PDQuTcWdd3zsLzVm-w
WARN  [2016-04-13 11:24:16,748] org.elasticsearch.discovery: [Thunderbolt] waited for 30s and no initial state was set by the discovery
INFO  [2016-04-13 11:24:16,748] org.elasticsearch.node: [Thunderbolt] started
</code></pre>