title: ElasticSearch Java API:NoNodeAvailableException: No node available
body: <pre><code>public static void main(String[] args) throws IOException {
      Settings settings = ImmutableSettings.settingsBuilder()
              .put("cluster.name", "foxzen")
              .put("node.name", "yu").build();
      Client client = new TransportClient(settings)
              .addTransportAddress(new InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9200));
              // XXX is my server's ip address
      IndexResponse response = client.prepareIndex("twitter", "tweet")
              .setSource(XContentFactory.jsonBuilder()
                      .startObject()
                      .field("productId", "1")
                      .field("productName", "XXX").endObject()).execute().actionGet();
      System.out.println(response.getIndex());
      System.out.println(response.getType());
      System.out.println(response.getVersion());
      client.close();
  }
  </code></pre>
  
  <p>I access server from my computer</p>
  
  <pre><code>curl -get http://XXX.XXX.XXX.XXX:9200/
  </code></pre>
  
  <p>get this</p>
  
  <pre><code>{
      "status" : 200,
      "name" : "yu",
      "version" : {
          "number" : "1.1.0",
          "build_hash" : "2181e113dea80b4a9e31e58e9686658a2d46e363",
          "build_timestamp" : "2014-03-25T15:59:51Z",
          "build_snapshot" : false,
          "lucene_version" : "4.7"
      },
      "tagline" : "You Know, for Search"
  }
  </code></pre>
  
  <p>Why get error by using Java API?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>There is the cluster and node part config of <code>elasticsearch.yml</code></p>
  
  <pre><code>################################### Cluster ###################################
  
  # Cluster name identifies your cluster for auto-discovery. If you're running
  # multiple clusters on the same network, make sure you're using unique names.
  #
  cluster.name: foxzen
  
  
  #################################### Node #####################################
  
  # Node names are generated dynamically on startup, so you're relieved
  # from configuring them manually. You can tie this node to a specific name:
  #
  node.name: yu
  </code></pre>