Skip to content

Add actuator health check support for Elasticsearch REST Clients #15174

@anthony-foulfoin

Description

@anthony-foulfoin

Hi,

Spring Boot 2.1 add auto-configurations for ElasticSearch RestClient and RestHighLevelClient.
It works well, but there is no actuator health check for the ES Rest clients.

There are two existing HealthIndicator for ES:

  • ElasticsearchHealthIndicator: it works only with the tcp client, not the rest one
  • ElasticsearchJestHealthIndicator: it works only with the Jest client

A solution would be to add an ElasticsearchRestHealthIndicator or to make the existing ElasticsearchHealthIndicator work with both tcp and rest clients.

For now, I use my own implementation:

@Component
public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {

	@Autowired
	private RestHighLevelClient client;

	@Override
	protected void doHealthCheck(Health.Builder builder) throws IOException {
		ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT);

		switch (response.getStatus()) {
			case GREEN:
			case YELLOW:
				builder.up();
				break;
			case RED:
			default:
				builder.down();
				break;
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions