Micronaut Elasticsearch

Integration between Micronaut and Elasticsearch


1 Introduction

Micronaut supports automatic configuration of Elasticsearch Java REST Client via the elasticsearch module.

2 Release History

For this project, you can find a list of releases (with release notes) here:

3 Configuration

Configuring the Elasticsearch Client

Using the CLI

If you are creating your project using the Micronaut CLI, supply the elasticsearch feature to configure the Elasticsearch Java REST Client in your project:

$ mn create-app my-app --features elasticsearch

To configure the Elasticsearch Java REST Client you should first add elasticsearch module to your classpath:

compile "io.micronaut.elasticsearch:micronaut-elasticsearch"

You should then configure the httpHosts of the Elasticsearch server you wish to communicate with in application.yml as:

  httpHosts: "http://localhost:9200,"

See the API for DefaultElasticsearchConfigurationProperties for more information on the available configuration options.

Once you have the above configuration in place then you can inject the org.elasticsearch.client.RestHighLevelClient or org.elasticsearch.client.RestClient bean. The following is the simplest way to get Elasticsearch information using the High Level REST Client:

MainResponse response =
        client.info(RequestOptions.DEFAULT) (1)
1 client is an instance of the org.elasticsearch.client.RestHighLevelClient bean.

For more information on executing different operations using Elasticsearch High Level REST Client please read the Elasticsearch Documentation.

Modify the Default Request Configurations

Often times you want to change the default configurations. To achieve this Micronaut, includes the ability to change the default request configurations. You can set the default request configurations under key elasticsearch.request.default as:

  httpHosts: http://localhost:9200,
      expectContinueEnabled: true

See the API RequestConfig.Builder for more information on the available configuration options.

Modify the HTTP Client Configurations

To modify the HTTP Client configurations (e.g. request timeouts, authentication, or anything that the HttpAsyncClientBuilder allows to set). You can define a bean using Factory which replaces org.apache.http.impl.nio.client.HttpAsyncClientBuilder.

Following is an example to change the default credentials provider:

import io.micronaut.context.annotation.Replaces
import org.apache.http.auth.AuthScope

static class HttpAsyncClientBuilderFactory {

    HttpAsyncClientBuilder builder() {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider()
                new UsernamePasswordCredentials("user", "password"))

        return HttpAsyncClientBuilder.create()

4 Health Checks

When the elasticsearch module is activated a ElasticsearchHealthIndicator is activated resulting in the /health endpoint and CurrentHealthStatus interface resolving the health of the Elasticsearch cluster.

The only configuration option supported is to enable or disable the indicator.

            enabled: false

See the section on the Health Endpoint for more information.

5 GraalVM Support

Micronaut Elasticsearch is compatible with GraalVM out of the box. The only thing needed is to add some dependencies to make logging work.

To enable the logging when running on the JVM:


Additional dependencies for logging on GraalVM:



See the section on GraalVM in the user guide for more information.

6 Repository

You can find the source code of this project in this repository: