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.
Let us learn about cat APIs more in detail in this chapter.
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
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
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
The count parameter provides the count of total number of documents in the entire cluster.
GET /_cat/count?v
On running the above code, we get the response as shown below −
epoch timestamp count 1557633536 03:58:56 17809