title: Java ElasticSearch example using TransportCilent
body: <p>The following code explains the communication between Java and ElasticSearch<br>
  using  Transport client. When I run I am getting  org.elasticsearch.nodedisconnectedException. Any clear example for the Java Elasticsearch given will be appreciated or anyone can help me in finding the solution.</p>
  
  <pre><code>public static Client function() {
      Settings setting = ImmutableSettings.settingsBuilder().put("cluster.name", "localtestsearch").build();
      client = new TransportClient();
      client = client.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
      return client;
  
  }
  
  public static void main(String[] args) {
  
      System.out.println("In Main Method");
  
      try {
          System.out.println("In try block");
          Client client = new TransportClient()
                  .addTransportAddress(new InetSocketTransportAddress("localhost",
                          9300));
  
  
          System.out.println("Connected");
  
          client.close();
  
          Settings settings = ImmutableSettings.settingsBuilder()
                  .put("client.transport.sniff", true).build();
          TransportClient client1 = new TransportClient(settings);
  
  
          org.elasticsearch.node.Node node = nodeBuilder().node();
          System.out.println("Node " + node);
  
          Client client = node.client();
  
          System.out.println("calling Client from Node " + client);
  
          node.close();
          System.out.println("Node CLosed");
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  
  }
  
  }
  </code></pre>