# Elasticsearch RestClient 7.4 - making SSL connection

**URL:** <https://discuss.elastic.co/t/elasticsearch-restclient-7-4-making-ssl-connection/203359>\
**Category:** Elasticsearch\
**Created:** [October 13, 2019, 9:26pm UTC](https://discuss.elastic.co/t/elasticsearch-restclient-7-4-making-ssl-connection/203359 "2019-10-13T21:26:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudhakar\_Tadepalli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudhakar_tadepalli/32/55827_2.png) [@Sudhakar\_Tadepalli](https://discuss.elastic.co/u/Sudhakar_Tadepalli)\
**Post date:** [October 13, 2019, 9:26pm UTC](https://discuss.elastic.co/t/elasticsearch-restclient-7-4-making-ssl-connection/203359/1 "2019-10-13T21:26:43Z")

</div>

HI, I am trying to connect to the elasticsearch server using basic credentials and receiving the "Unrecognized SSL message, plaintext connection?" error.

Appreciate your help. Thanks!

```
if (restClient == null) {
		try {
			Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"), new BasicHeader("Role", "Read")};
			final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
			credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("email@domain.com", "password"));

					restClient = RestClient.builder(new HttpHost("myhost", "9200" "https")).setDefaultHeaders(headers)
					.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
						public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
							httpClientBuilder.disableAuthCaching(); //if received 401 , then try sending authentication, if not,reuse previous credentials.
							
							return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
						}
					}).build();

		}catch (Exception e	){
			System.out.println("Error Creating RestClient:" + e.getMessage());
		}

	}
return restClient;
}
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 14, 2019, 11:52am UTC](https://discuss.elastic.co/t/elasticsearch-restclient-7-4-making-ssl-connection/203359/2 "2019-10-14T11:52:34Z")

</div>

Does your Elasticsearch cluster have TLS/https enabled? If not, you might need to change the `HttpHost` parameter from `https` to `http`.

--Alex

---

<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:** [November 11, 2019, 11:52am UTC](https://discuss.elastic.co/t/elasticsearch-restclient-7-4-making-ssl-connection/203359/3 "2019-11-11T11:52:38Z")

</div>

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