Example application

There is an example application at ebean-orm-examples/example-elastic which you can investigate / clone etc.

Dependencies

Add ebean-elastic as a dependency to your project. This will automatically register with Ebean as the document store implementation.

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-elastic</artifactId>
  <version>12.2.1</version>
</dependency>

Bean mapping

On each of the entity beans that we want to have indexed in ElasticSearch add the @DocStore annotation.

Additionally we can add mapping for:

  • @DocCode on properties that should not be analysed
  • @DocSortable on properties that we want both analysed and not analysed
  • @DocEmbedded to include embedded documents (denormalise) for @ManyToOne and @OneToMany properties

Refer to mapping for more details.

Generated index mapping

At this point Ebean is able to generate mapping JSON for each bean type annotated with @DocStore.

Properties
ebean.docstore.url=http://127.0.0.1:9200
ebean.docstore.active=true
ebean.docstore.generateMapping=true
ebean.docstore.dropCreate=true
#ebean.docstore.create=true

ebean.docstore.url is required and specifies the url of the ElasticSearch server to use. Currently the alternative of using the native transport is not supported.

ebean.docstore.active is required to be set to true to indicate the document store integration is active.

If ebean.docstore.generateMapping is set to true Ebean will generate mapping files for each index and these will by default be generated into src/main/resources under elastic-mapping.

When ebean.docstore.dropCreate is set to true when Ebean starts it will drop and re-create all the indexes. Alternatively we can use ebean.docstore.create to create only indexes that have not already been defined.

Refer to Mapping generation for more details.

Review issues on github

Review the issues logged against the ebean-elastic to see what currently is not supported, future enhancements etc.