How to use the RestHighLevelClient for the cloud?

I use the Java RestHighLevelClient, and it works fine with localhost elastic search (in which I pass "localhost" and 9200, "http") like the example in here

But how do I use this for elastic search cloud? and I suppose the host would be "" and my port will be "9203" and scheme is always "https"?

There is a user/password associated with the cloud version... how to pass that along?

This is happening in the Low Level client. See

Here is a sample code I'm using:

Note that decodeUrl() is basically returning the host url like

Thank you!

The following works perfectly fine in a little standalone Java Application (where the constants are pointing to my instance)...

    RestHighLevelClient restHighLevelClient = null;
    if (!"localhost".equals(ELASTIC_HOST)) {

        RestClientBuilder builder = RestClient
                .builder(new HttpHost(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), ELASTIC_SCHEME));

        // if not localhost, specify username and password
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                new UsernamePasswordCredentials(ELASTIC_USER, ELASTIC_PASSWORD));

                httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
        builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(40000).setSocketTimeout(50000)).setMaxRetryTimeoutMillis(60001);

        restHighLevelClient = new RestHighLevelClient(builder);

    } else {
        restHighLevelClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), "http")));

    try {"ping");
        boolean pingResult =;"pingResult=" + pingResult);
    } catch (Exception e) {
        LOGGER.error("Can't even ping: ",e);

However, inside a Web application (in a data access object)... this ping will fail (and any search, show indices etc would also fail) with a Timeout.

03-21-2019 12:20:55 ERROR ElasticsearchDAO:388 - Can't even ping: listener timeout after waiting for [60001] ms
	at org.elasticsearch.client.RestClient$SyncResponseListener.get(
	at org.elasticsearch.client.RestClient.performRequest(
	at org.elasticsearch.client.RestHighLevelClient.performRequest(

Any idea what extra steps a Java web application may need to access elastic search on cloud?

The only thing that I can think about would be a conflicting dependency or something like this.
What is the web server you are deploying this app to?

Thanks. I am using Wildfly 10. I also tried using "http" with 9200, and same result...

Is there any way to print debug all classes to see what is happening?
Or at least org.elasticsearch and org.apache packages?

Thanks @dadoonet, yes, conflicting maven artifact was the culprit.
I was able to use mvn dependency:tree to figure that elastic search uses a particular version of apache httpcomponent which uses a particular version of commons-codec... and I had another place that uses a different version which conflicted it.

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