CAT API
1.0 版引入
您可以使用紧凑对齐文本 (CAT) API 获取有关集群的基本统计信息,这些信息以易于理解的表格格式呈现。CAT API 是一种人类可读的接口,它返回纯文本而不是传统的 JSON 格式。
使用 CAT API,您可以回答诸如哪个节点是选定的主节点、集群处于什么状态、每个索引中有多少文档等问题。
示例
要查看 CAT API 中可用的操作,请使用以下命令
GET _cat
响应是一个 ASCII 猫 (=^.^=
) 和一个操作列表
=^.^=
/_cat/allocation
/_cat/segment_replication
/_cat/segment_replication/{index}
/_cat/shards
/_cat/shards/{index}
/_cat/cluster_manager
/_cat/nodes
/_cat/tasks
/_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/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/pit_segments
/_cat/pit_segments/{pit_id}
可选查询参数
根 _cat
API 不接受任何参数,但单个 API(例如 /_cat/nodes
)接受以下查询参数。
参数 | 描述 |
---|---|
v | 通过向列添加标题来提供详细输出。它还添加了一些格式以帮助对齐每个列。本节中的所有示例都包含 v 参数。 |
help | 列出给定操作的默认和其他可用标题。 |
h | 将输出限制为特定标题。 |
format | 返回结果的格式。有效值包括 json 、yaml 、cbor 和 smile 。 |
s | 按指定列对输出进行排序。 |
查询参数使用示例
您可以为任何 CAT 操作指定查询参数以获得更具体的结果。
获取详细输出
要查询别名并获取包含响应中所有列标题的详细输出,请使用 v
查询参数。
GET _cat/aliases?v
响应提供了更多详细信息,例如响应中每列的名称。
alias index filter routing.index routing.search is_write_index
.kibana .kibana_1 - - - -
sample-alias1 sample-index-1 - - - -
如果没有详细参数 v
,响应只会返回别名名称
.kibana .kibana_1 - - - -
sample-alias1 sample-index-1 - - - -
获取所有可用标题
要查看所有可用标题,请使用 help
参数
GET _cat/<operation_name>?help
例如,要查看 CAT 别名操作的可用标题,请发送以下请求
GET _cat/aliases?help
响应包含可用标题
alias | a | alias name
index | i,idx | index alias points to
filter | f,fi | filter
routing.index | ri,routingIndex | index routing
routing.search | rs,routingSearch | search routing
is_write_index | w,isWriteIndex | write index
获取部分标题
要将输出限制为标题的子集,请使用 h
参数
GET _cat/<operation_name>?h=<header_name_1>,<header_name_2>&v
例如,要将别名限制为仅别名名称和索引,请发送以下请求
GET _cat/aliases?h=alias,index
响应包含所请求的信息
.kibana .kibana_1
sample-alias1 sample-index-1
通常,对于任何操作,您可以使用 help
参数查找可用标题,然后使用 h
参数将输出限制为您关心的标题。
按标题排序
要按标题对输出进行排序,请使用 s
参数
GET _cat/<operation_name>?s=<header_name_1>,<header_name_2>
例如,要按别名然后按索引对别名进行排序,请发送以下请求
GET _cat/aliases?s=i,a
响应包含所请求的信息
sample-alias2 sample-index-1
sample-alias1 sample-index-2
以 JSON 格式检索数据
默认情况下,CAT API 以 text/plain
格式返回数据。
要以 JSON 格式检索数据,请使用 format=json
参数
GET _cat/<operation_name>?format=json
例如,要以 JSON 格式检索别名,请发送以下请求
GET _cat/aliases?format=json
响应包含 JSON 格式的数据
[
{"alias":".kibana","index":".kibana_1","filter":"-","routing.index":"-","routing.search":"-","is_write_index":"-"},
{"alias":"sample-alias-1","index":"sample-index-1","filter":"-","routing.index":"-","routing.search":"-","is_write_index":"-"}
]
如果您使用安全插件,请确保您拥有相应的权限。