Elasticsearch 简明教程
Elasticsearch - Cat APIs
通常,各种 Elasticsearch API 的结果都以 JSON 格式显示。但是,JSON 并不总是易于阅读。所以,Elasticsearch 提供了 cat API 功能,它有助于采用更易于阅读和理解的格式来打印结果。cat API 中有各种各样的参数,它们服务于不同的用途,例如 - 用语 V 可使输出详细。
Usually the results from various Elasticsearch APIs are displayed in JSON format. But JSON is not easy to read always. So cat APIs feature is available in Elasticsearch helps in taking care of giving an easier to read and comprehend printing format of the results. There are various parameters used in cat API which server different purpose, for example - the term V makes the output verbose.
让我们在这章中更详细地了解 cat API。
Let us learn about cat APIs more in detail in this chapter.
Verbose
详细输出对 cat 命令的结果进行漂亮的显示。在下面给出的示例中,我们将获得集群中存在的各个指标的详细信息。
The verbose output gives a nice display of results of a cat command. In the example given below, we get the details of various indices present in the cluster.
GET /_cat/indices?v
在运行以上代码时,我们得到响应,如下所示:-
On running the above code, we get the response as shown below −
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open schools RkMyEn2SQ4yUgzT6EQYuAA 1 1 2 1 21.6kb 21.6kb
yellow open index_4_analysis zVmZdM1sTV61YJYrNXf1gg 1 1 0 0 283b 283b
yellow open sensor-2018-01-01 KIrrHwABRB-ilGqTu3OaVQ 1 1 1 0 4.2kb 4.2kb
yellow open colleges 3ExJbdl2R1qDLssIkwDAug 1 1 0 0 283b 283b
Headers
h 参数,也称为标题,用于仅显示该命令中提到的那些列。
The h parameter, also called header, is used to display only those columns mentioned in the command.
GET /_cat/nodes?h=ip,port
在运行以上代码时,我们得到响应,如下所示:-
On running the above code, we get the response as shown below −
127.0.0.1 9300
Sort
sort 命令接受查询字符串,该字符串可以按查询中指定的列对表格进行排序。默认排序为升序,但这可以通过向一列添加 :desc 来进行更改。
The sort command accepts query string which can sort the table by specified column in the query. The default sort is ascending but this can be changed by adding :desc to a column.
以下示例给出了按已编制索引模式排序且呈降序排列的模板的结果。
The below example, gives a result of templates arranged in descending order of the filed index patterns.
GET _cat/templates?v&s=order:desc,index_patterns
在运行以上代码时,我们得到响应,如下所示:-
On running the above code, we get the response as shown below −
name index_patterns order version
.triggered_watches [.triggered_watches*] 2147483647
.watch-history-9 [.watcher-history-9*] 2147483647
.watches [.watches*] 2147483647
.kibana_task_manager [.kibana_task_manager] 0 7000099