java.net.ConnectException while connection to cloud elasticsearch instance

Please make your code looking like this:

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 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:

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:

HTH