Controlling cluster health via the API

In the Understanding clusters, replication, and sharding recipe in Chapter 1, Getting Started, we discussed the ElasticSearch cluster and how to manage red and yellow states.

ElasticSearch provides a convenient way to manage cluster state, which is one of the first things to check in case of problems.

Getting ready

You need a working ElasticSearch cluster.

How to do it...

To control cluster health, we will perform the following steps:

  1. To view cluster health, the HTTP method is GET and the curl command is:
    curl -XGET 'http://localhost:9200/_cluster/health?pretty'
  2. The result will be:
    { "cluster_name" : "elasticsearch", "status" : "green", "timed_out" : false, "number_of_nodes" : 2, "number_of_data_nodes" : 2, "active_primary_shards" ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.