Elasticsearch通過使用JSON來作為溝通的數據格式,這對於開發者來說很友好,因為很多程序都支持JSON格式。比如js就不說了,Java也有fastjson,ruby什么的都自帶json。
Elasticsearch中信息很多,如果單憑肉眼來尋找復雜數據之間的關系,是很困難的。因此cat命令應運而生,它幫助開發者快速查詢Elasticsearch的相關信息。
_cat命令
通過使用_cat可以查看支持的命令:
$ curl localhost:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
verbose
每個命令都支持使用?v參數,來顯示詳細的信息:
$ curl localhost:9200/_cat/master?v
id host ip node
QG6QrX32QSi8C3-xQmrSoA 127.0.0.1 127.0.0.1 Manslaughter
help
每個命令都支持使用help參數,來輸出可以顯示的列:
$ curl localhost:9200/_cat/master?help
id | | node id
host | h | host name
ip | | ip address
node | n | node name
headers
通過h參數,可以指定輸出的字段:
$ curl localhost:9200/_cat/master?v
id host ip node
QG6QrX32QSi8C3-xQmrSoA 127.0.0.1 127.0.0.1 Manslaughter
$ curl localhost:9200/_cat/master?h=host,ip,node
127.0.0.1 127.0.0.1 Manslaughter
數字類型的格式化
很多的命令都支持返回可讀性的大小數字,比如使用mb或者kb來表示。
$ curl localhost:9200/_cat/indices?v
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open test 5 1 3 0 9.2kb 9.2kb