how to use embedded ElasticSearch for integration testing how to use embedded ElasticSearch for integration testing elasticsearch elasticsearch

how to use embedded ElasticSearch for integration testing


First you need to keep in mind that newer versions of elasticsearch have dropped support to use it embedded, reasons for that are described in this blog post.

On many versions of Elasticsearch, including elastic 5, you could use ESIntegTestCase support class and make your integration test class extend it in order to have support of embedded Elasticsearch on tests. You can read more about this at their official documentation.

From their official docs:

public class Mytests extends ESIntegTestCase {  @Override  protected Settings nodeSettings(int nodeOrdinal) {      return Settings.builder().put(super.nodeSettings(nodeOrdinal))             .put("node.mode", "network")             .build();  }}

In version 1.x there was a class named ElasticsearchTestCase that would give support for unit testing with elastic, check this link on their official repository for a full example on how to use it.


Embedded elasticsearch is not supported anymore

You can use this maven dependency, it will start elasticsearch 6 cluster for you

<dependency>    <groupId>org.elasticsearch-6</groupId>    <artifactId>elasticsearch-embedded-cluster</artifactId>    <version>1.0-SNAPSHOT</version></dependency>

You can read more details on https://github.com/nitishgoyal13/elasticsearch-6-embedded-cluster