Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.joschi.dropwizard.elasticsearch.health;
 
 
 import java.util.List;
 
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

A com.codahale.metrics.health.HealthCheck which checks if one or more indices exist in Elasticsearch.

See also:
Admin Indices Indices Exists
public class EsIndexExistsHealthCheck extends HealthCheck {
    private final Client client;
    private final String[] indices;

    
Construct a new Elasticsearch index exists health check.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indices a java.util.List of indices in Elasticsearch which should be checked
Throws:
java.lang.IllegalArgumentException if indices was null or empty
    public EsIndexExistsHealthCheck(Client clientList<Stringindices) {
        checkArgument(!indices.isEmpty(), "At least one index must be given");
        this. = checkNotNull(client);
        this. = checkNotNull(indices.toArray(new String[indices.size()]));
    }

    
Construct a new Elasticsearch index exists health check.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indexName the index in Elasticsearch which should be checked
    public EsIndexExistsHealthCheck(Client clientString indexName) {
        this(client, ImmutableList.of(indexName));
    }

    
Perform a check of the number of documents in the Elasticsearch indices.

Returns:
if the Elasticsearch indices exist, a healthy com.codahale.metrics.health.HealthCheck.Result; otherwise, an unhealthy com.codahale.metrics.health.HealthCheck.Result with a descriptive error message or exception
Throws:
java.lang.Exception if there is an unhandled error during the health check; this will result in a failed health check
    @Override
    protected Result check() throws Exception {
        final IndicesExistsResponse indicesExistsResponse = .admin().indices().prepareExists().get();
        if (indicesExistsResponse.isExists()) {
            return Result.healthy();
        } else {
            return Result.unhealthy("One or more indices do not exist.");
        }
    }
New to GrepCode? Check out our FAQ X