The ElasticSearch add-on allows you to configure, inject and use ElasticSearch clients.

<dependency>
    <groupId>org.seedstack.addons.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
</dependency>
Show version
dependencies {
    compile("org.seedstack.addons.elasticsearch:elasticsearch:2.1.0")
}

Main features:

  • Embedded indexes,
  • Remote indexes.

More information about the ElasticSearch Java API here

Configuration

To access an ElasticSearch index, you need to declare a client in configuration. Multiple clients can be configured. They must be listed in the following property:

org.seedstack.elasticsearch.clients = client1, client2, ...

Remote instance

To access a remote ElasticSearch index, you need to specify the host(s) of one or more node(s) of the ElasticSearch cluster:

[org.seedstack.elasticsearch.client.client1]
hosts = host1:port1, host2:port2, ...

You can omit the port in which case will be set to the ElasticSearch default (9300).

Embedded instance

If you don’t specify the hosts property, a local ElasticSearch node will be created and stored in the persistence-elasticsearch/{client-name} subdirectory of the Seed local storage location, where {client-name} is the name of the ElasticSearch client.

Other options

You can specify any configuration property of the ElasticSearch client with the following syntax:

[org.seedstack.elasticsearch.client.client1]
property.name.of.elasticsearch.property = value

Usage

To use a configured ElasticSearch client, simply inject it where needed:

@Inject
@Named("client1")
Client client1;

Example

Configuration for an embedded ElasticSearch instance:

org.seedstack.elasticsearch.clients = test

[org.seedstack.elasticsearch.client.test]
property.cluster.name = test-cluster-1

To inject this configured client, use the following syntax:

@Inject
@Named("test")
Client testClient;