# NoNodeAvailableException when using Java client

**URL:** <https://discuss.elastic.co/t/nonodeavailableexception-when-using-java-client/72388>\
**Category:** Elasticsearch\
**Created:** [January 22, 2017, 10:53am UTC](https://discuss.elastic.co/t/nonodeavailableexception-when-using-java-client/72388 "2017-01-22T10:53:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![doopey](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@doopey](https://discuss.elastic.co/u/doopey)\
**Post date:** [January 22, 2017, 10:53am UTC](https://discuss.elastic.co/t/nonodeavailableexception-when-using-java-client/72388/1 "2017-01-22T10:53:54Z")

</div>

I've got a NoNodeAvailableException while using Java Transport Client to connect with Elasticsearch 5.1.1. However I've also seen many topics here with the same title and I have no idea to solve this problem.  
The NoNodeAvailableException is given below.

> NoNodeAvailableException[None of the configured nodes were available: [{c3-miui-assist-fe10.assist-search}{lhxqrIimSkGBYbxKxuf1UQ}{0Pgd3xXfRpyoT3jyERSGPQ}{10.114.35.4}{10.114.35.4:9300}]]; nested: SendRequestTransportException[[c3-miui-assist-fe10.assist-search][10.114.35.4:9300][indices:data/read/search]]; nested: NodeNotConnectedException[[c3-miui-assist-fe10.assist-search][10.114.35.4:9300] Node not connected];  
> at org.elasticsearch.client.transport.TransportClientNodesService$RetryListener.onFailure(TransportClientNodesService.java:272)  
> at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:51)  
> at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:984)  
> at org.elasticsearch.transport.TransportService$5.doRun(TransportService.java:552)  
> at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527)  
> at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)  
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
> at java.lang.Thread.run(Thread.java:745)  
> Caused by: SendRequestTransportException[[c3-miui-assist-fe10.assist-search][10.114.35.4:9300][indices:data/read/search]]; nested: NodeNotConnectedException[[c3-miui-assist-fe10.assist-search][10.114.35.4:9300] Node not connected];  
> at org.elasticsearch.transport.TransportService.sendRequestInternal(TransportService.java:531)  
> at org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:465)  
> at org.elasticsearch.action.TransportActionNodeProxy.execute(TransportActionNodeProxy.java:51)  
> at org.elasticsearch.client.transport.TransportProxyClient.lambda$execute$0(TransportProxyClient.java:59)  
> at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:231)  
> at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)  
> at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:345)  
> at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)  
> at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)  
> at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)

Here is my code:

```
@Service
public class ESProxy {

	private Client client;

	private static Logger logger = LoggerFactory.getLogger(ESProxy.class);

	@PostConstruct
	public void init() {
	    logger.info("start to init elasticsearch client");
		Properties properties = System.getProperties();
		Resource res = new ClassPathResource("es.properties");
		try {
			properties.load(res.getInputStream());
			String clusterName = properties.getProperty("cluster.name");
			String sniff = properties.getProperty("client.transport.sniff");
			String hosts = properties.getProperty("hosts");
			String port = properties.getProperty("port");
			String userPasswd = properties.getProperty("xpack.security.user");
			String[] cols = hosts.split(",");
            TransportAddress[] addresses = new TransportAddress[cols.length];
			for (int i = 0; i < cols.length; i++) {
				addresses[i] = new InetSocketTransportAddress(InetAddress.getByName(cols[i]), Integer.valueOf(port));
			}
            Settings settings = Settings.builder()
                    .put("cluster.name", clusterName)
                    .put("xpack.security.user", userPasswd)
                    .put("client.transport.sniff", Boolean.valueOf(sniff))
                    .build();
			TransportClient client = new PreBuiltXPackTransportClient(settings).addTransportAddresses(addresses);
			this.client = client;
		} catch (IOException e) {
			logger.error("{}", e);
            e.printStackTrace();
		}
	}
	
	public Client getClient() {
		return this.client;
	}
	
	@PreDestroy
	public void destroy() {
		logger.info("destroy the client");
		this.client.close();
	}
}

```

and I just use the following code to use this proxy.

```
String queryStr = "{\"match\":{\"split_word\":{\"query\":\""+ passage +"\"}}}";
SearchResponse response = esProxy.getClient().prepareSearch("pastime_detail").setQuery(QueryBuilders.wrapperQuery(queryStr)).setSize(3).execute().actionGet();

```

The cluster.name, the port and the hosts are the same as the configuration in elasticsearch.yml.  
Then I deployed this service on the server. After getting the right response for the first two times, I was stuck in the NoNodeAvailableException above. But after about 20 seconds, I could get the right response again. And then the NoNodeAvailableException appeared when I send another requests.  
I am so confused. Anyone can help me to solve this problem?

---

<div class="post-metadata">

**Author:** ![doopey](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@doopey](https://discuss.elastic.co/u/doopey)\
**Post date:** [January 22, 2017, 10:54am UTC](https://discuss.elastic.co/t/nonodeavailableexception-when-using-java-client/72388/2 "2017-01-22T10:54:27Z")

</div>

here's part of my pom.xml:

```
<dependencies>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>x-pack-api</artifactId>
        <version>5.1.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>5.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>x-pack-transport</artifactId>
        <version>5.1.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-to-slf4j</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>com.unboundid</groupId>
        <artifactId>unboundid-ldapsdk</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.56</version>
    </dependency>
    <dependency>
        <groupId>com.xiaomi.misearch</groupId>
        <artifactId>liferec-thrift</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 19, 2017, 10:54am UTC](https://discuss.elastic.co/t/nonodeavailableexception-when-using-java-client/72388/3 "2017-02-19T10:54:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
