1. cat APIs

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cat.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/cat+APIs

贡献者 : 那伊抹微笑

1.1. Introduction(介绍)

对于计算机来说,JSON 是一种很好的格式,虽然它便于打印,但是尝试找出潜在的数据关系是比较麻烦的。人们的眼睛,特别是在一个 ssh 终端看东西时,需要紧凑的,对齐的文本。该 cat API 的目标就是为了满足这种需求。

所有的 cat 命令接受一个查询字符串的参数 help 以看到它提供的所有的 header(头部)和其它的信息,以及单个的 /_cat 命令可以列出所有可用的命令。

1.2. 常见参数

1.2.1. Verbose(详细的)

每个命令都可以接受一个查询字符串参数 v 以在运行时输出更详细的信息。例如 :

curl -XGET 'localhost:9200/_cat/master?v&pretty'

可能会响应 :

id                     host      ip        node
u_n93zwxThWHi1PDBJAGAg 127.0.0.1 127.0.0.1 u_n93zw

1.2.2. Help(帮助)

每个命令都可以接受一个查询字符串参数 help,它将输出命令中可用的列。例如 :

curl -XGET 'localhost:9200/_cat/master?help&pretty'

可能响应如下 :

id   |   | node id
host | h | host name
ip   |   | ip address
node | n | node name

1.2.3. Headers(页眉)

每个命令都可以接受一个查询字符串参数 h,它将会强制只显示那些出现的列。例如 :

curl -XGET 'localhost:9200/_cat/nodes?h=ip,port,heapPercent,name&pretty'

响应如下 :

127.0.0.1 9300 27 sLBaIGK

您也可以像 /_cat/thread_pool?h=ip,bulk.* 这样从 bulk.. 这里开始使用简单的通配符请求多个列以获取所有的 header(页眉或者别名)。

1.2.4. Numberic formats(数字格式)

许多命令提供了一个数字输出的类型,可能是一个字节,大小,或者时间值。默认情况下,这些类型对于人们是友好的格式,例如,3.5mb(而不是 3763212),但是却不适合排序。所以为了可以在这些值上进行操作,顺序是很重要的,您必须改变它的格式。

假设您想找出集群中最大的索引(使用分片存储,而不是文档的数量)。/_cat/indices API 是可以做到的。我们只需要调整两件事情。首先,我们希望关闭对人们友好的模式。我们就可以使用 byte-level(字节级别)的原理。然后我们使用合适的列将我们的输出重定向到 sort 中。下面的例子演示了根据第8列数值的大小按照降序排序 :

% curl '192.168.56.10:9200/_cat/indices?bytes=b' | sort -rnk8
green wiki2 3 0 10000   0 105274918 105274918
green wiki1 3 0 10000 413 103776272 103776272
green foo   1 0   227   0   2065131   2065131

如果您希望改变 time units,请使用 time 参数。

如果您希望改变 size units,请使用 size 参数。

如果您希望改变 byte units,请使用 bytes 参数。

1.2.5. Response as text, json, smile, yaml or cbor(作为 text, json, smile, yaml 或者 cbor 格式响应)

% curl 'localhost:9200/_cat/indices?format=json&pretty'
[
  {
    "pri.store.size": "650b",
    "health": "yellow",
    "status": "open",
    "index": "twitter",
    "pri": "5",
    "rep": "1",
    "docs.count": "0",
    "docs.deleted": "0",
    "store.size": "650b"
  }
]

当前支持的格式(为 ?format= 参数): - text(默认)- json - smile - yaml - cbor。此外,还可以设置 “AcceptHTTP header 到相应的媒体格式。以上所有格式都支持,GET 参数优先于 header。例如 :

% curl '192.168.56.10:9200/_cat/indices?pretty' -H "Accept: application/json"
[
  {
    "pri.store.size": "650b",
    "health": "yellow",
    "status": "open",
    "index": "twitter",
    "pri": "5",
    "rep": "1",
    "docs.count": "0",
    "docs.deleted": "0",
    "store.size": "650b"
  }
]
Copyright © Kilvn 2021. all right reserved,powered by Gitbook最后更新时间: 2021-06-08 20:22:42

results matching ""

    No results matching ""