# Elasticsearch High Rest Client

**URL:** <https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773>\
**Category:** Elasticsearch\
**Created:** [July 26, 2018, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773 "2018-07-26T12:59:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandra0651](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chandra0651/32/30484_2.png) [@chandra0651](https://discuss.elastic.co/u/chandra0651)\
**Post date:** [July 26, 2018, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773/1 "2018-07-26T12:59:27Z")

</div>

I am new to writing the Client for ES , some how i was able to figure out to write basic client in java, can some one help me out how to pass credentials and self signed certificates

```
private static class RestHighLevelClientHelper {
	private static final RestHighLevelClient CLIENT = new RestHighLevelClient(
			RestClient.builder(
					new HttpHost("localhost", 9200, "http"),
					new HttpHost("localhost", 9201, "http")));
}

public static RestHighLevelClient getElasticSearchClientInstance() {
	return RestHighLevelClientHelper.CLIENT;
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 26, 2018, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773/2 "2018-07-26T13:28:05Z")

</div>

Start here: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/\_basic\_authentication.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html)

---

<div class="post-metadata">

**Author:** ![Mingchih\_Lin](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Mingchih\_Lin](https://discuss.elastic.co/u/Mingchih_Lin)\
**Post date:** [July 27, 2018, 6:03pm UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773/3 "2018-07-27T18:03:58Z")

</div>

Hi,  
I have a similar issue connecting to elastic cloud. I followed the instructions how to set high-level client.  
The problem i have is "Connection reset by peer". Could you help me with this issue? I tried to search online about how to connect to elastic cloud, but I failed to find any. Thank you.

Code below does work with regular ES node I installed on ami linux image.

Code:  
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();  
credentialsProvider.setCredentials(AuthScope.ANY,  
new UsernamePasswordCredentials("username", "password"));

```
    RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243));
    lowRestClient = builder.build();
    highLevelClient = new RestHighLevelClient(builder);
   CreateIndexRequest request = new CreateIndexRequest("index-abc");
   CreateIndexResponse createIndexResponse = highLevelClient.indices().create(request);

```

Exception in thread "main" java.io.IOException: **Connection reset by peer**  
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:728)  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:198)  
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:522)  
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:508)  
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:99)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 28, 2018, 9:27am UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773/4 "2018-07-28T09:27:53Z")

</div>

@Mingchih_Lin It would be better to open your own question as it's a different problem.  
Will be easier for other users to find it IMO. Also, would be lovely if you format your code to make it nicer to read. (See [https://discuss.elastic.co/c/elasticsearch](https://discuss.elastic.co/c/elasticsearch))

Anyway, you need probably to change:

```auto
RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243));

```

to

```auto
RestClientBuilder builder = RestClient.builder(new HttpHost("clusterId.us-east-1.aws.found.io", 9243, "https"));

```

---

<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:** [August 25, 2018, 9:28am UTC](https://discuss.elastic.co/t/elasticsearch-high-rest-client/141773/5 "2018-08-25T09:28:08Z")

</div>

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