# java.net.ConnectException while connection to cloud elasticsearch instance

**URL:** <https://discuss.elastic.co/t/java-net-connectexception-while-connection-to-cloud-elasticsearch-instance/170501>\
**Category:** Elasticsearch\
**Created:** [March 1, 2019, 1:06pm UTC](https://discuss.elastic.co/t/java-net-connectexception-while-connection-to-cloud-elasticsearch-instance/170501 "2019-03-01T13:06:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [March 2, 2019, 11:04am UTC](https://discuss.elastic.co/t/java-net-connectexception-while-connection-to-cloud-elasticsearch-instance/170501/4 "2019-03-02T11:04:25Z")

</div>

Please make your code looking like this:

```auto
public RestHighLevelClient createClientV2() {
  final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  // ...
}

```

That's definitely easier to read...

So please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Anyway, here is some code that might help. It's using a 6.6 client but that should be similar:

> <https://github.com/dadoonet/fscrawler/blob/master/elasticsearch-client/elasticsearch-client-v6/src/main/java/fr/pilato/elasticsearch/crawler/fs/client/v6/ElasticsearchClientV6.java#L406-L420>

HTH

---

_[View the full topic](https://discuss.elastic.co/t/java-net-connectexception-while-connection-to-cloud-elasticsearch-instance/170501)._
