ElasticSearch

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

Dependency

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

Configuration

To access an ElasticSearch index, you need to declare a client in configuration. Multiple clients can be configured:

elasticSearch:
  # Configured ElasticSearch clients with the client name as key
  clients:
    client1:
      # List of hosts the client will connect to
      hosts: (List<String>)
      
      # Properties used for client configuration
      properties:
        property1: value1
        
      # Set of ElasticSearch plugin classes to enable for this client  
      plugins: Set<Class<? extends Plugin>>

To dump the elasticSearch configuration options:

mvn -q -Dargs="elasticSearch" seedstack:config

Usage

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

public class SomeClass {
    @Inject
    @Named("client1")
    private Client client1;
}

You can find more information about the ElasticSearch Java API here.

Example

Configuration for an ElasticSearch server on the same machine:

elasticSearch:
  clients:
    client1: localhost

This client is used like this:

public class SomeClass {
    @Inject
    @Named("client1")
    private Client client1;
}

On this page


Edit this page