title: ElasticSearch client connection impossible
body: <p>I am having problems with ElasticSearch Client.</p>
  
  <p>I have designed a Java application (to finish my developer studies) that manage different databases MySQL, mongoDb and ElasticSearch. 
  I was able to read, create and update data from a db to another.
  All was designed and coded with local databases and everything works very well.
  All the tests have been validated so we decide to make it work on distant servers on the real databases.</p>
  
  <p>And then the problems begin to happened, and especially the one i'm stuck with since two long days and i'm getting really desperate.</p>
  
  <ul>
  <li><p>With TransportClient it worked on local, but on real server it bring a NoNodeAvailableException saying that none of the configured nodes are available. Have try a lot of things to make it work but it doesn't.</p></li>
  <li><p>So i decide to try connect and request with REST. Here is my code, and the error i got is not very detailed : it's a ConnectException.</p></li>
  </ul>
  
  <p>Code :</p>
  
  <pre><code>    // Get the connection client from ES database
      public static RestHighLevelClient getConnection()
      {
          // Singleton
          if(client == null)
          {
              try             
              {       
                  // Set Credz
                  final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                  credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("Login", "pwd"));             
  
                  // Builder
                  RestClientBuilder builder = RestClient.builder(new HttpHost("ServerIP", 9200, "http")).setHttpClientConfigCallback(new HttpClientConfigCallback() 
                  {
                      @Override
                      public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) 
                      {   
                          System.out.println("Setting taken !");
                          return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                      }
                  });                 
  
                  // Create client
                  client = new RestHighLevelClient (builder);
  
                  ClusterHealthRequest healthReq = new ClusterHealthRequest("looppy-cluster");
                  ClusterHealthResponse response = client.cluster().health(healthReq, RequestOptions.DEFAULT);
      int numberOfNodes = response.getNumberOfNodes(); 
              System.out.println("Nodes Nb : " + numberOfNodes);
  
              } 
              catch(Exception ex)
              {   
  System.out.println("Client connection problem");
                  ex.printStackTrace();
              }
          }       
  
          return client;
      }   
  </code></pre>
  
  <p>And here is the exception i got : </p>
  
  <pre><code>    java.net.ConnectException
      at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943)
      at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227)
      at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1256)
      at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1231)
      at org.elasticsearch.client.ClusterClient.health(ClusterClient.java:146)
      at utils.ElasticSearchMng.getConnection(ElasticSearchMng.java:86)
      at utils.ElasticSearchMng.getLoopiesFromES(ElasticSearchMng.java:133)
      at program.Program$1.run(Program.java:96)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$500(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  Caused by: java.net.ConnectException
      at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:168)
      at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:561)
      at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:822)
      at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:183)
      at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:210)
      at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:155)
      at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348)
      at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:192)
      at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I'm getting despered and ireally don't understand what's happening, would appreciate a lot if someone can help !</p>
  
  <p>thx a lot guyz</p>