Not able connect with Rest High Level Client in ESIntegTestCase of ElasticSearch 7.0.0


I have written some integration tests for my project which uses ElasticSearch as database.

I was using Rest High Level Client with ElasticSearch version 6.6.0. But recently I upgraded the version to 7.0.0. Now, my Integration tests are failing to connect with ElasticSearch on Rest High Level Client. Earlier with 6.6.0, I was using setting to enable HTTP. But now it's deprecated and somehow the HTTP is not getting enabled. It seems nodes created by ESIntegTestCase do not have HTTP enabled by default.

Error Timeout connecting to [/]



Test class

package com.rp;

import com.carrotsearch.randomizedtesting.RandomizedRunner;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.transport.Netty4Plugin;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.Collection;

import static com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope.NONE;

@ClusterScope(numDataNodes = 1)
public class CommonUtilTests extends ESIntegTestCase {

    private RestHighLevelClient esClient;

    protected Settings nodeSettings(int nodeOrdinal) {
        return Settings.builder()

    protected Collection<Class<? extends Plugin>> nodePlugins() {
        final Collection<Class<? extends Plugin>> plugins = new ArrayList<>();
        return plugins;

    public void initialize() {
        esClient = new RestHighLevelClient(RestClient.builder(getRestClient().getNodes().get(0)));

    public void test_createIndex() throws IOException {
        Boolean isCreated = CommonUtil.createIndex(esClient, "my-index");

How can I get RestHighLevelClient in ESIntegTestCase?

ESIntegTestCase is meant for internal whitebox testing of Elasticsearch nodes and clustering. For users testing external behavior with Elasticsearch, we recommend standing up a real elasticsearch node and/or multi node cluster. This will allow you to then use the RestHighLevelClient, just as your normal application would.

Yes. But I wanted to run some unit tests with in memory or embedded ES. In previous version 6.6.0 I was able to use testing framework to start embedded cluster and run my unit tests.

I had to enable the HTTP using HTTP_ENABLED flag.

Now is there any way to get the same thing working with this version? Because I cannot start separate cluster for these tests.

You can not run elasticsearch embedded. Read this blog post.

Note that to run integration tests (not unit tests) you would probably prefer running that in something close to a production environment, like a real elasticsearch server instance. I shared some ideas about integration testing in this thread: In memory testing with RestHighLevelClient

Also this sample project shows how to use Elasticsearch Test Classes:

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

I have confirm the solution posted here works for High Level Rest Client Integration Tests with single node embedded in 7.6.