Home » DevOps » A Complete And Easy Guide To Check Elasticsearch

A Complete And Easy Guide To Check Elasticsearch

To poll Elasticsearch db status, we usually need to learn and try many many REST API. When we’re new, it would take quite a while to put all the pieces together.

As Ops/DevOps, we are usually more concerned about cluster health and data inside. Enclosed is A Simple Step-By-Step Guide to check elasticsearch. Cluster, Nodes, Shards, Indices, Documents And Beyond.


Original Article: http://dennyzhang.com/query_elasticsearch



Impatient users can jump to our Elasticsearch Cheat Sheet at the bottom.

1. Basic Intro About Elasticsearch

Generally speaking, elasticsearch is an efficient and API friendly search engine based on Lucene.

Some key concepts to know, before we dive deeper.

  • Cluster: a collection of ES nodes.
  • Nodes: server/instance stores data or coordinate with indexing and search capabilities.
  • Index: a collection of documents. Like tables in MySQL.
  • Type: To ensure optimal performance, we can define mappings for data types.
  • Document: a basic unit of information. Like record in SQL.
  • Shards: It allows us to horizontally split a big index, and store in multiple nodes.

2. GUI Tool: elasticsearch-head

elasticsearch-head is a web front end for browsing and interacting with an Elastic Search cluster1. It is pretty much like phpMyAdmin for mysql2. By default, elasticsearch doesn’t install this plugin.

Though its UI looks a bit primitive and less attracting, it’s certainly a useful tool for dummies like me. I frequently use the “Structured Query” menu to grab some random records, in order to understand unfamiliar ES indices.


3. Elasticsearch Global Info By API

Time for complicated, yet powerful REST API.

  • Check cluster health.
curl \


Usually we pay attention to “status” field, which should be green. When it’s yellow, probably we have unassigned shards or unavailable nodes. When it’s red, all primary shards of certain indices are inactive. This is truely bad.

  • Check global setting and cluster stats3.
# Get version
curl http://localhost:9200

# Get global settings
curl \

# Poll cluster stats
curl http://localhost:9200/_stats?pretty

Get version by CLI, without starting ES service.

bin/elasticsearch --version

  • List nodes and shards
# List nodes
curl http://localhost:9200/_cat/nodes?v

# List shards
curl http://localhost:9200/_cat/shards?v

  • Show elasticsearch slow query4: As DevOps/Ops, we definitely want to be on top of this. To enable this, make sure elasticsearch.yml is proplery configured. Tips: If you have problems to verify your setting about this, temporarily change thresholds to zero. Then every fetch operation should generate a slow log.

4. Check Elasticsearch Index By API

  • Show Basic Summary Of An Elasticsearch Index
curl \


“count” indicates how many records in the index. “_shards” shows how the index is horizontally split.

  • Check DB schema of An Index or A field.
# Get Index Mapping
curl \

# Get Field Mapping
curl \

  • Indices verbose statistics.5.
curl \

5. Check Documents Inside indices

  • Get all documents of an index. Be careful with big indices. You might get tons of output running this command.
curl \

  • Full Text Search
# Get documents contains 50
curl \

  • URI Search: filter by field.6 URI search indicates parsing request parameters from URI.
# Get documents whose f1 is 50
curl \

  • Get documents with paging mechanism.7
# Get iterator, fetching 2 records each time
curl \
-d '{
    "query" : {
        "match_all" : {}

# Get scroll id from previous command
# Then keep polling records of next page
curl 'localhost:9200/_search/scroll'  \
-d' {
    "scroll" : "1m", 
    "scroll_id" : "INPUT_YOUR_SCROLL_ID" 
  • Advanced Search With Request Body.8 This would fall into the realm of lucene now.
curl \
 -d '{
    "query": {
        {"query": "(field1:value1) 
            AND (field2:value2)"}

6. More Tools To Recommend

  • elasticdump is a 3rd tools to import and export elasticsearch indices9. Since it’s a npm module, we have to install nodejs/npm to use it. Frankly speaking, this is not my preference. And elasticsearch has built-in support, called snapshot10.However I would still recommand elasticdump for small indices. Why? Snapshot a bit complicated than I would expect. And we have to configure elasticsearch.yml and restart es instances to take effect. Too intruding. Compared to elasticdump, I wish elasticsearch can have more native support in the future version.

7. Recap today’s discussion: Elasticsearch Cheat Sheet

What To Check Summary
elasticsearch-head1 A web tool
elasticdump7 Import and export tools
Get Version localhost:9200
Version By CLI bin/elasticsearch –version
Cluster health localhost:9200/_cluster/health?pretty
List Nodes localhost:9200/_cat/nodes?v
List shards localhost:9200/_cat/shards?v
List indices localhost:9200/_cat/indices?v
Indice Summary localhost:9200/$index/_count?pretty
Indice Stats localhost:9200/$index/_stats?pretty
Get all docs localhost:9200/$index/_search?pretty
Full Text Search localhost:9200/$index/_search?q=50
Search By field localhost:9200/$index/_search?q=f1:50
Search By 2 fields localhost:9200/$index/_search?q=”f1:v1&f2=v2″

More Reading: How To Install ELK Stack With Any Given Version.


3 www.elastic.co/guide/en/elasticsearch/reference/current/cluster-stats.html
4 www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html
5 www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
6 www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
7 www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
8 www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html
10 www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

Like our blog posts? Discuss with us on LinkedInTwitter Or NewsLetter.