0
0
ElasticsearchHow-ToBeginner · 3 min read

How to Check Cluster Stats in Elasticsearch Quickly

To check cluster stats in Elasticsearch, use the GET _cluster/stats API endpoint. This returns detailed information about your cluster's health, nodes, indices, and more in JSON format.
📐

Syntax

The basic syntax to get cluster stats is a simple HTTP GET request to the _cluster/stats endpoint.

  • GET: The HTTP method to retrieve data.
  • _cluster/stats: The API endpoint that returns cluster statistics.
http
GET /_cluster/stats
💻

Example

This example shows how to request cluster stats using curl from the command line. The output is a JSON object with detailed cluster information.

bash
curl -X GET "http://localhost:9200/_cluster/stats?pretty"
Output
{ "cluster_name" : "my-elasticsearch-cluster", "status" : "green", "indices" : { "count" : 5, "shards" : { "total" : 10, "primaries" : 5, "replication" : 1.0 }, "docs" : { "count" : 10000, "deleted" : 0 }, "store" : { "size_in_bytes" : 123456789 } }, "nodes" : { "count" : { "total" : 3, "data" : 3, "master" : 1 }, "versions" : [ "8.6.0" ] } }
⚠️

Common Pitfalls

Common mistakes when checking cluster stats include:

  • Using the wrong endpoint like _cluster/health which gives health info but not full stats.
  • Not including the ?pretty parameter, which makes JSON output hard to read.
  • Trying to access the API without proper permissions or from a wrong host/port.

Always ensure your Elasticsearch server is running and accessible.

bash
curl -X GET "http://localhost:9200/_cluster/health?pretty"  # This shows health, not full stats

curl -X GET "http://localhost:9200/_cluster/stats"  # Correct endpoint but add ?pretty for readability
📊

Quick Reference

CommandDescription
GET /_cluster/statsReturns detailed cluster statistics
GET /_cluster/healthReturns cluster health status only
?prettyFormats JSON output for readability
curl -X GET "http://localhost:9200/_cluster/stats?pretty"Example command to get readable cluster stats

Key Takeaways

Use the GET _cluster/stats API to get detailed cluster statistics in Elasticsearch.
Add ?pretty to the URL to make JSON output easier to read.
Ensure you have proper access and the Elasticsearch server is running.
Do not confuse _cluster/stats with _cluster/health; they provide different info.
Use curl or Kibana Dev Tools to run the cluster stats query.