title: Why can't I connect to ElasticSearch through Java API?
body: <p>I'm having trouble connecting to vanilla ElasticSearch cluster via the Java API.</p>
  
  <p>To reproduce:</p>
  
  <pre><code>#start elasticsearch
  elasticsearch -f
  
  #checking in a new window
  $ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{\
      "user" : "kimchy",\
      "post_date" : "2009-11-15T14:12:12",\
      "message" : "trying out Elastic Search"\
  }'
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>{
    "ok": true,
    "_index": "twitter",
    "_type": "tweet",
    "_id": "1",
    "_version": 3
  }
  </code></pre>
  
  <hr>
  
  <pre><code>$ curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy'
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>{
    "took": 2,
    "timed_out": false,
    "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
    },
    "hits": {
      "total": 1,
      "max_score": 0.30685282,
      "hits": [
        {
          "_index": "twitter",
          "_type": "tweet",
          "_id": "1",
          "_score": 0.30685282,
          "_source": {
            "user": "kimchy",
            "post_date": "2009-11-15T14:12:12",
            "message": "trying out Elastic Search"
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>So, everything works via HTTP. Trying via Java (per <a href="http://www.elasticsearch.org/guide/reference/java-api/client/" rel="nofollow noreferrer">this page</a>):</p>
  
  <pre><code>public static void main(String[] args) {
  
      Client client = new TransportClient()
      .addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
  
      IndexResponse response = null;
      try {
        response = client.prepareIndex("twitter", "tweet", "1")
            .setSource(XContentFactory.jsonBuilder()
                        .startObject()
                            .field("user", "john")
                            .field("postDate", new Date())
                            .field("message", "who dont it work")
                        .endObject()
                      )
            .execute()
            .actionGet();
      } catch (ElasticSearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
  
      System.out.println(response);
  }
  </code></pre>
  
  <p>And I get the following stack trace:</p>
  
  <pre><code>May 21, 2013 8:27:42 AM org.elasticsearch.plugins
  INFO: [Bes] loaded [], sites []
  May 21, 2013 8:27:49 AM org.elasticsearch.client.transport
  INFO: [Bes] failed to get node info for [#transport#-1][inet[localhost/127.0.0.1:9200]], disconnecting...
  org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster/nodes/info] request_id [0] timed out after [5002ms]
      at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:342)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:680)
  Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: No node available
      at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:202)
      at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
      at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:84)
      at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:310)
      at org.elasticsearch.action.index.IndexRequestBuilder.doExecute(IndexRequestBuilder.java:315)
      at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62)
      at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57)
      at Scratch.main(Scratch.java:30)
  </code></pre>
  
  <p>And closest thing I've found so far to this problem is <a href="http://elasticsearch-users.115913.n3.nabble.com/No-node-available-Exception-td3920119.html" rel="nofollow noreferrer">here</a>, but the thread trailed off without resolution.</p>