title: Speed up Elasticsearch Test Containers
body: <p>I have moved the java integration tests to use elasticsearch test containers instead of using embedded elasticsearch. The tests have become slower by 1 hour which is a huge productivity hit. I am looking for ways to speed that up.</p>
  <p>I tried using params like <code>reuse</code> on Elasticsearch container but that didn't make a dent. My latest configuration is</p>
  <pre><code>    private static final String ELASTICSEARCH_VERSION = &quot;7.11.2&quot;;
      private static ElasticsearchContainer elasticsearchContainer;
      private static final DockerImageName ELASTICSEARCH_IMAGE =
            DockerImageName
                  .parse(&quot;docker.elastic.co/elasticsearch/elasticsearch&quot;)
                  .withTag(ELASTICSEARCH_VERSION);
  </code></pre>
  <pre><code>            elasticsearchContainer = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
                    .withEnv(&quot;foo&quot;, &quot;bar&quot;).withSharedMemorySize(1000000000L);
              elasticsearchContainer.addExposedPorts(9200, 9300);
              elasticsearchContainer.withStartupTimeout(Duration.of(5, ChronoUnit.MINUTES));
              elasticsearchContainer.start();
  </code></pre>
  <pre><code>    private static RestHighLevelClient getRestHighLevelClient(ElasticsearchContainer container) {
          final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
          credentialsProvider.setCredentials(AuthScope.ANY,
                                             new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME,
                                                                             ELASTICSEARCH_PASSWORD));
          RestClientBuilder restClientBuilder = RestClient.builder(HttpHost.create(container.getHttpHostAddress()))
                .setHttpClientConfigCallback(httpClientBuilder -&gt; httpClientBuilder
                      .setDefaultCredentialsProvider(credentialsProvider)
                      .setKeepAliveStrategy((response, context) -&gt; 3 * 60 * 1000));
          // Try to prevent SocketTimeoutException when fetching larger batch size
          restClientBuilder.setRequestConfigCallback(
                requestConfigBuilder -&gt; requestConfigBuilder.setSocketTimeout(2 * 60 * 1000));
  
          return new RestHighLevelClient(restClientBuilder);
      }
  </code></pre>
  <p>Gradle config (gradle daemon crashed once so increased to 2g)</p>
  <pre><code>org.gradle.jvmargs=-Xms2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
  </code></pre>
  <p>Any suggestions on making the tests faster?</p>