Class ElasticsearchContainer

java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<ElasticsearchContainer>
org.testcontainers.elasticsearch.ElasticsearchContainer
All Implemented Interfaces:
AutoCloseable, org.junit.rules.TestRule, org.testcontainers.containers.Container<ElasticsearchContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class ElasticsearchContainer extends org.testcontainers.containers.GenericContainer<ElasticsearchContainer>
Testcontainers implementation for Elasticsearch.

Supported image: docker.elastic.co/elasticsearch/elasticsearch, elasticsearch

Exposed ports:

  • HTTP: 9200
  • TCP Transport: 9300
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Deprecated.
    static final String
    Elasticsearch Default Password for Elasticsearch >= 8

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    ElasticsearchContainer(String dockerImageName)
    Create an Elasticsearch Container by passing the full docker image name
    ElasticsearchContainer(org.testcontainers.utility.DockerImageName dockerImageName)
    Create an Elasticsearch Container by passing the full docker image name
  • Method Summary

    Modifier and Type
    Method
    Description
    Optional<byte[]>
    If this is running above Elasticsearch 8, this will return the probably self-signed CA cert that has been extracted
    A SSL context based on the self-signed CA, so that using this SSL Context allows to connect to the Elasticsearch service
     
    Deprecated.
    withCertPath(String certPath)
    Configure a CA cert path that is not the default
    withPassword(String password)
    Define the Elasticsearch password to set.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Field Details

  • Constructor Details

    • ElasticsearchContainer

      @Deprecated public ElasticsearchContainer()
    • ElasticsearchContainer

      public ElasticsearchContainer(String dockerImageName)
      Create an Elasticsearch Container by passing the full docker image name
      Parameters:
      dockerImageName - Full docker image name as a String, like: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
    • ElasticsearchContainer

      public ElasticsearchContainer(org.testcontainers.utility.DockerImageName dockerImageName)
      Create an Elasticsearch Container by passing the full docker image name
      Parameters:
      dockerImageName - Full docker image name as a DockerImageName, like: DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:7.9.2")
  • Method Details

    • caCertAsBytes

      public Optional<byte[]> caCertAsBytes()
      If this is running above Elasticsearch 8, this will return the probably self-signed CA cert that has been extracted
      Returns:
      byte array optional containing the CA cert extracted from the docker container
    • createSslContextFromCa

      public SSLContext createSslContextFromCa()
      A SSL context based on the self-signed CA, so that using this SSL Context allows to connect to the Elasticsearch service
      Returns:
      a customized SSL Context
    • withPassword

      public ElasticsearchContainer withPassword(String password)
      Define the Elasticsearch password to set. It enables security behind the scene for major version below 8.0.0. It's not possible to use security with the oss image.
      Parameters:
      password - Password to set
      Returns:
      this
    • withCertPath

      public ElasticsearchContainer withCertPath(String certPath)
      Configure a CA cert path that is not the default
      Parameters:
      certPath - Path to the CA certificate within the Docker container to extract it from after start up
      Returns:
      this
    • getHttpHostAddress

      public String getHttpHostAddress()
    • getTcpHost

      @Deprecated public InetSocketAddress getTcpHost()
      Deprecated.