Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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" : 5,
      "active_shards" : 10,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0
    }

How it works...

Every ElasticSearch node keeps the cluster status. The status can be of three types:

  • green...