To use ElasticSearch as Ebean's document store, we need to add configuration
for ebean.docstore properties like the example below:
To test using an ElasticSearch docker container, we set ebean.docstore.elastic.version
property. ebean-test will then ensure that ElasticSearch is running
as a docker container.
ebean: test: platform: h2 ddlMode: dropCreate # none | dropCreate | migrations | create dbName: myapp docstore: url: http://127.0.0.1:9201 active: true generateMapping: true dropCreate: true elastic: # For testing using docker container version: 5.6.0 port: 9201
In terms of logging we can see:
21:57:06.587 INFO io.ebean.docker.commands.Commands - Start container ut_elastic with port:9201
When using ElasticSearch by itself and not with another database leave out the ebean.test.platform
section like:
ebean: docstore: url: http://127.0.0.1:9201 active: true generateMapping: true dropCreate: true elastic: version: 5.6.0 port: 9201
ebean-elastic dependency
Add ebean-elastic as a dependency.
<dependency> <groupId>io.ebean</groupId> <artifactId>ebean-elastic</artifactId> <version>13.0.0</version> </dependency>
Configuration properties
| Property | Description |
|---|---|
| ebean.docstore.active | Set to true to enable docstore use |
| ebean.docstore.url | URL that ElasticSearch is using |
| ebean.docstore.generateMapping | When true generate the index mapping |
| ebean.docstore.dropCreate | When true drop the indexes and recreate them |
For more details on the ElasticSearch.
Docker container
We can programmatically start a docker container version of ElasticContainer.
The following example uses the ebean-test-docker dependency which already comes with ebean-test.
If we do not have a dependency on ebean-test, then add io.ebean:ebean-test-docker:5.0
as a dependency.
package main; import io.ebean.docker.commands.ElasticContainer; public class Main { public static void main(String[] args) { ElasticContainer container = ElasticContainer.newBuilder("5.6.0") .build(); container.start(); } }