Useful Commands for Elasticsearch Administration
Useful Commands for Elasticsearch Administration
Display all the Index
Use the cat indices API to get the following information for each index in a cluster:
- Shard count
- Document count
- Deleted document count
- Primary store size
- Total store size of all shards, including shard replicas
To list all index in a cluster
curl -X GET 'http://localhost:9200/_cat/indices?v'
curl -X GET "localhost:9200/_cat/indices/*?v&s=index&pretty"
[root@elasticsearchserver ~]# curl -X GET "localhost:9200/_cat/indices/*?v&s=index&pretty"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .apm-agent-configuration wZqqGeFkTWKOQ2MqAOcD4Q 1 0 0 0 283b 283b
green open .kibana_1 wZsvvNI1TFKc1tiHcETkQw 1 0 5 1 24kb 24kb
green open .kibana_2 7MnJjkJ5RDKd7Oi3-IZnaQ 1 0 169 24 106.4kb 106.4kb
green open .kibana_task_manager_1 XYnMBeqDRKmpL8VdoaoWNQ 1 0 2 0 6.9kb 6.9kb
green open .kibana_task_manager_2 fdSAP8H-SBW4FtsPaTMIfg 1 0 3 2 33.9kb 33.9kb
green open .tasks Ao9gSR_6ToKB1_3LefiqxA 1 0 1 0 6.6kb 6.6kb
yellow open prod-2020.03.24 c-0ejTgbTKG3tqKaY3GU0A 1 1 100 0 54.3kb 54.3kb
To list Specific index in a cluster
curl -X GET "localhost:9200/_cat/indices/proderrors*?v&s=index&pretty"
[root@elasticsearchserver ~]# curl -X GET "localhost:9200/_cat/indices/proderrors*?v&s=index&pretty"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open proderrors-2020.03.24 hgXqiRE9Rc68ZUDk4sUcLA 1 1 1217 0 542.5kb 542.5kb
yellow open proderrors-2020.03.25 mT4Kv-2sRcGbEFK0789rkQ 1 1 458 0 258.7kb 258.7kb
yellow open proderrors-2020.03.26 0QN2OlldSQukSus4AgGmMQ 1 1 313 0 189.5kb 189.5kb
yellow open proderrors-2020.03.27 u12P7SFATfK41RXyVEqKXQ 1 1 308 0 187.9kb 187.9kb
yellow open proderrors-2020.03.28 D4tHjkyFSHqWd45nkjWgug 1 1 313 0 190.1kb 190.1kb
yellow open proderrors-2020.03.29 Jdd8JtBMTFiPBg6VIvazKQ 1 1 313 0 189.9kb 189.9kb
Delete An indexhealth status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open proderrors-2020.03.24 hgXqiRE9Rc68ZUDk4sUcLA 1 1 1217 0 542.5kb 542.5kb
yellow open proderrors-2020.03.25 mT4Kv-2sRcGbEFK0789rkQ 1 1 458 0 258.7kb 258.7kb
yellow open proderrors-2020.03.26 0QN2OlldSQukSus4AgGmMQ 1 1 313 0 189.5kb 189.5kb
yellow open proderrors-2020.03.27 u12P7SFATfK41RXyVEqKXQ 1 1 308 0 187.9kb 187.9kb
yellow open proderrors-2020.03.28 D4tHjkyFSHqWd45nkjWgug 1 1 313 0 190.1kb 190.1kb
yellow open proderrors-2020.03.29 Jdd8JtBMTFiPBg6VIvazKQ 1 1 313 0 189.9kb 189.9kb
Index named "proderrors-2020.03.29" will be deleted by following command:
curl -X DELETE 'http://localhost:9200/proderrors-2020.03.29'
curl -X GET 'http://localhost:9200/proderrors-2020.03.29/_search'
All Elasticsearch fields are indexes.
curl -X GET http://localhost:9200/proderrors-2020.03.29?pretty
[root@elasticsearchserver ~]# curl -X GET http://localhost:9200/proderrors-2020.03.29?pretty
{
"proderrors-2020.03.29" : {
"aliases" : { },
"mappings" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"docker" : {
"properties" : {
"container_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"kubernetes" : {
"properties" : {
"container_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"namespace_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pod_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"log" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"stream" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"tag" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1588442296530",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "Jdd8JtBMTFiPBg6VIvazKQ",
"version" : {
"created" : "7060299"
},
"provided_name" : "proderrors-2020.03.29"
}
}
}
}
[root@elasticsearchserver ~]#
Access ElasticSearch with Basic Authentication{
"proderrors-2020.03.29" : {
"aliases" : { },
"mappings" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"docker" : {
"properties" : {
"container_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"kubernetes" : {
"properties" : {
"container_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"namespace_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pod_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"log" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"stream" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"tag" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1588442296530",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "Jdd8JtBMTFiPBg6VIvazKQ",
"version" : {
"created" : "7060299"
},
"provided_name" : "proderrors-2020.03.29"
}
}
}
}
[root@elasticsearchserver ~]#
If you have turned on security with ElasticSearch then you need to supply the user and password like shown below to every curl command
curl -X GET 'http://localhost:9200/_cat/indices?v' -u elastic:(password)
[root@elasticsearchserver ~]# curl -X GET 'http://localhost:9200/_cat/indices?v' -u admin:password
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana_task_manager_2 fdSAP8H-SBW4FtsPaTMIfg 1 0 3 2 33.9kb 33.9kb
green open .kibana_task_manager_1 XYnMBeqDRKmpL8VdoaoWNQ 1 0 2 0 6.9kb 6.9kb
green open .tasks Ao9gSR_6ToKB1_3LefiqxA 1 0 1 0 6.6kb 6.6kb
yellow open prod-2020.04.02 CEpSOBiiTAWEviGWSFET8A 1 1 340 0 110.7kb 110.7kb
yellow open prod-2020.04.03 aAI-sQd6Rs6ra5-LThWccw 1 1 49 0 35.8kb 35.8kb
yellow open prod-2020.04.04 _fUG9yCkRfKq99nnkDB5KA 1 1 57 0 48.1kb 48.1kb
yellow open prod-2020.04.05 1w1WcB63RnSLIt3lkmbEeA 1 1 52 0 45.5kb 45.5kb
Backup an indexhealth status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .kibana_task_manager_2 fdSAP8H-SBW4FtsPaTMIfg 1 0 3 2 33.9kb 33.9kb
green open .kibana_task_manager_1 XYnMBeqDRKmpL8VdoaoWNQ 1 0 2 0 6.9kb 6.9kb
green open .tasks Ao9gSR_6ToKB1_3LefiqxA 1 0 1 0 6.6kb 6.6kb
yellow open prod-2020.04.02 CEpSOBiiTAWEviGWSFET8A 1 1 340 0 110.7kb 110.7kb
yellow open prod-2020.04.03 aAI-sQd6Rs6ra5-LThWccw 1 1 49 0 35.8kb 35.8kb
yellow open prod-2020.04.04 _fUG9yCkRfKq99nnkDB5KA 1 1 57 0 48.1kb 48.1kb
yellow open prod-2020.04.05 1w1WcB63RnSLIt3lkmbEeA 1 1 52 0 45.5kb 45.5kb
curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/_reindex -d '{
"source": {
"index": "prod-2020.04.05"
},
"dest": {
"index": "prod-2020.04.05_backup"
}
}'
"source": {
"index": "prod-2020.04.05"
},
"dest": {
"index": "prod-2020.04.05_backup"
}
}'
[root@elasticsearchserver ~]# curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/_reindex -d '{
> "source": {
> "index": "prod-2020.04.05"
> },
> "dest": {
> "index": "prod-2020.04.05_backup"
> }
> }'
{"took":126,"timed_out":false,"total":52,"updated":0,"created":52,"deleted":0,"batches":1,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[]}[root@elasticsearchserver ~]#
[root@elasticsearchserver ~]#
Check the newly created Index :> "source": {
> "index": "prod-2020.04.05"
> },
> "dest": {
> "index": "prod-2020.04.05_backup"
> }
> }'
{"took":126,"timed_out":false,"total":52,"updated":0,"created":52,"deleted":0,"batches":1,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[]}[root@elasticsearchserver ~]#
[root@elasticsearchserver ~]#
[root@elasticsearchserver ~]# curl -X GET "localhost:9200/_cat/indices/prod-2020.04.05*?v&s=index&pretty"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open prod-2020.04.05 1w1WcB63RnSLIt3lkmbEeA 1 1 52 0 45.5kb 45.5kb
yellow open prod-2020.04.05_backup ku-9eQHER1a73VhOIyH_kQ 1 1 52 0 30.4kb 30.4kb
[root@elasticsearchserver ~]#
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open prod-2020.04.05 1w1WcB63RnSLIt3lkmbEeA 1 1 52 0 45.5kb 45.5kb
yellow open prod-2020.04.05_backup ku-9eQHER1a73VhOIyH_kQ 1 1 52 0 30.4kb 30.4kb
[root@elasticsearchserver ~]#
No comments