Skip to content

Elasticsearch

Cluster health check

# localhost without auth
curl localhost:9200/_cluster/health?pretty

# auth by password
curl -k --user user:password "https://10.0.0.1:9200/_cluster/health?pretty"

Indexes

# list
curl localhost:9200/_cat/indices

# delete
curl -X DELETE localhost:9200/{index_name}

Shards

$ curl localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host       ip         node
    43        2.4gb     9.1gb    990.8gb    999.9gb            0 10.0.10.16 10.0.10.16 elk_elasticsearch.2
     1       20.3kb     6.8gb    993.1gb    999.9gb            0 10.0.10.15 10.0.10.15 elk_elasticsearch.1
    43        2.4gb     9.6gb    990.3gb    999.9gb            0 10.0.10.14 10.0.10.14 elk_elasticsearch.3
     2                                                                                 UNASSIGNED

$ curl localhost:9200/_cat/shards?v
index                              shard prirep state         docs   store ip         node
.monitoring-es-7-2021.04.03        0     p      STARTED     224680 121.1mb 10.0.10.12 elk_elasticsearch.3
.monitoring-logstash-7-2021.04.02  0     r      STARTED    1805568 323.5mb 10.0.10.12 elk_elasticsearch.3
...
.kibana_task_manager_1             0     r      STARTED          6   2.3mb 10.0.10.12 elk_elasticsearch.3
.kibana_1                          0     r      UNASSIGNED                            
.kibana_1                          0     p      UNASSIGNED   

Dump indexes

Source: https://github.com/elasticsearch-dump/elasticsearch-dump

# pull image
$ docker pull elasticdump/elasticsearch-dump

# dump 
$ docker run --rm -ti --network host elasticdump/elasticsearch-dump --input=http://localhost:9200/my_index --output=$ | gzip > my_index.json.gz

# restore
docker run --rm -i --network host elasticdump/elasticsearch-dump --output=http://localhost:9200/my_index --input=$ < my_index.json

Repositories and Snapshots

# list repositories
curl localhost:9200/_cat/repositories

# create repo
curl -X PUT localhost:9200/_snapshot/{repo_name} -H "Content-Type: application/json" -d '{"type": "fs","settings": {"location": "{path_on_fs}"}}'

# get repo info
 curl -s localhost:9200/_snapshot/{repo_name}

# create snapshot for few indexes
curl -X PUT localhost:9200/_snapshot/{repo_name}/{snapshot_name} -H "Content-Type: application/json" -d '{"indices": "{index_name_a},{index_name_b}"}'

# restore index from snapshot
# index should be deleted before restoring
curl -X POST localhost:9200/_snapshot/{repo_name}/{snapshot_name}/_restore