# RestClient 6.1 getting Connection reset by peer error while querying ES

**URL:** <https://discuss.elastic.co/t/restclient-6-1-getting-connection-reset-by-peer-error-while-querying-es/122824>\
**Category:** Elasticsearch\
**Created:** [March 7, 2018, 6:13am UTC](https://discuss.elastic.co/t/restclient-6-1-getting-connection-reset-by-peer-error-while-querying-es/122824 "2018-03-07T06:13:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arun\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Arun\_Kumar1](https://discuss.elastic.co/u/Arun_Kumar1)\
**Post date:** [March 7, 2018, 6:13am UTC](https://discuss.elastic.co/t/restclient-6-1-getting-connection-reset-by-peer-error-while-querying-es/122824/1 "2018-03-07T06:13:40Z")

</div>

I am getting " Connection reset by peer" error while querying ES. after few re-tries its working fine.  
private static RestHighLevelClient client;

```
     RestClientBuilder builder = RestClient.builder(new HttpHost(hostname, 9200, "http"));
			builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            });		
		client = new RestHighLevelClient(builder);

```

The exception is too big to share here. Is there another way that i can upload the exception?

**The connection is established by**

```
private static RestHighLevelClient getRestInstance() throws exception{
	
		if (client == null) {

			initializeRestClient(); //this calls the restClientbuilder to initialize the connection. 
		}
		return client;
	}

```

**Search**  
`searchResponse = getRestInstance().search(searchRequest); // this line throws the exception.`

---

<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:** [April 4, 2018, 6:17am UTC](https://discuss.elastic.co/t/restclient-6-1-getting-connection-reset-by-peer-error-while-querying-es/122824/3 "2018-04-04T06:17:00Z")

</div>

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