Elasticsearch container

This module helps running elasticsearch using Testcontainers.

Note that it's based on the official Docker image provided by elastic.

Usage example

You can start an elasticsearch container instance from any Java application by using:

// Create the elasticsearch container.
ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:6.4.1");

// Start the container. This step might take some time...

// Do whatever you want here.
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "changeme"));
RestClient client = RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
        .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider))
Response response = client.performRequest("GET", "/");

// Stop the container.

Note that if you are still using the TransportClient (not recommended as deprecated), the default cluster name is set to docker-cluster so you need to change cluster.name setting or set client.transport.ignore_cluster_name to true.

Choose your Elasticsearch license

If you prefer to start a Docker image with the pure OSS version (which means with no security or other advanced features), you can use this instead:

// Create the elasticsearch container.
ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.1");

results matching ""

    No results matching ""