Connecting to Elasticsearch with Java

I’m using the Java API, but I keep getting this error:

org.elasticsearch.client.transport.NoNodeAvailableException: None of the
configured nodes are available:

Even if I run my code on the same machine as Elasticsearch I get
this error.

Any ideas why this is? I was able to make contact once, then it
stopped.

Here is my TransportClient implementation. I decided to place
the code on the server to be sure, still no good.

I’ve tried several implementations with the put method. With and
without cluster.name or network.host:

public class ClientTransport {
    
public Client client;

@SuppressWarnings("resource")
public ClientTransport(){
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "store_cluster").put("network.host","127.0.0.1").build();
             
this.client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("http://127.0.0.1", 9300));
    
           }
 
    }

Here is usage of the ClientTransport class:

public static void main(String[]
args){
Map<String, Object> json = new
HashMap<String, Object>();
json.put("user","kimchy");
json.put("postDate",new Date());
json.put("message","trying out Elasticsearch");

IndexResponse response = null;
ClientTransport c = new
ClientTransport();

             
for(int x = 0;x<10;x++){

response = c.client.prepareIndex("twitter2", "tweet").setSource(json).execute().actionGet();
                  
System.out.println("Index: "+response.getIndex());              
System.out.println("Type: "+response.getType());                
System.out.println("Id: "+response.getId());                 
System.out.println("Is Created: "+response.isCreated());        
}

          
//do I need to fluch data?      
//client.admin().indices().flush(new
FlushRequest('location').refresh(true)).actionGet()
c.client.close();
}

Make sure the Elasticsearch version in your client application is the same version as the Elasticsearch instance you're running.

Change this

this.client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));

Same error:

org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available:

using 1.4.4 on both the server and my code.
Here are my libraries on the server and my code.

Your settings don't look quite right remove the "network.host" property:

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();

I removed network.host.
Still no good.

Is that the correct cluster name?

Yes, names are all correctly matched.

Here is a simplified version of your code that works. Copy, compile and run it (you'll need to change the cluster name). Hopefully from this example your can figure out what is wrong with your original code.

public static void main(String args[]) {
	Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();
	Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300));
	
	Map<String, Object> json = new HashMap<String, Object>();
	json.put("user","kimchy");
	json.put("postDate",new Date());
	json.put("message","trying out Elasticsearch");

	IndexResponse response = null;
				 
	for(int x = 0;x<10;x++){
	  response = client.prepareIndex("test", "tweet").setSource(json).execute().actionGet();
						
	  System.out.println("Index: "+response.getIndex());              
	  System.out.println("Type: "+response.getType());                
	  System.out.println("Id: "+response.getId());                 
	  System.out.println("Is Created: "+response.isCreated());        
	}  
	
	//do I need to fluch data?      
	//client.admin().indices().flush(new
	//FlushRequest("location").refresh(true).actionGet();
	client.close();
}

I have downloaded a default ES, ran it on a MAC and then tried to connect with the above code copied and run with no changes and still get this.

NoNodeAvailableException: None of the configured nodes are available.

I am not sure if I am missing something or if the code is out of date vs most recent versions.

I am running ES 2.1.0.

I went back to version 1.7.1 of ES and the same code worked out of the box. No issues. I have read this is a version issue with v 2 of ES. Is that the case, if so is there an issue open about this?

Ok. I have worked this out.

Both the Cleint JAR and the ES version need to be the same.

Spring-Data-Elasticsearch (1.3.1) only works on version 1.5.2 of ES Server and bundles with it theES 1.5.2 Java API.

So thats why the error is happening.

Currently Spring are looking into this but dont have a timeline on support.

https://jira.spring.io/browse/DATAES-211

Hope this helps anyone looking for the details on this.

So its a case of coding directly with the ES API or sticking to ES 1.5.2 for now.

I have the similar issue, I am running both client and server using ES 2.1.2 version, this is interesting when I run Java client program on ES server it works fine, if move client to another server I get this exception.
Any solution

I have the same version of ES in my local and server. But still i get the no node exception.