cat.asciidoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. [[cat]]
  2. == cat APIs
  3. ["float",id="intro"]
  4. === Introduction
  5. JSON is great... for computers. Even if it's pretty-printed, trying
  6. to find relationships in the data is tedious. Human eyes, especially
  7. when looking at a terminal, need compact and aligned text. The cat API
  8. aims to meet this need.
  9. All the cat commands accept a query string parameter `help` to see all
  10. the headers and info they provide, and the `/_cat` command alone lists all
  11. the available commands.
  12. [float]
  13. [[common-parameters]]
  14. === Common parameters
  15. [float]
  16. [[verbose]]
  17. ==== Verbose
  18. Each of the commands accepts a query string parameter `v` to turn on
  19. verbose output. For example:
  20. [source,js]
  21. --------------------------------------------------
  22. GET /_cat/master?v
  23. --------------------------------------------------
  24. // CONSOLE
  25. Might respond with:
  26. [source,txt]
  27. --------------------------------------------------
  28. id host ip node
  29. u_n93zwxThWHi1PDBJAGAg 127.0.0.1 127.0.0.1 u_n93zw
  30. --------------------------------------------------
  31. // TESTRESPONSE[s/u_n93zw(xThWHi1PDBJAGAg)?/.+/ non_json]
  32. [float]
  33. [[help]]
  34. ==== Help
  35. Each of the commands accepts a query string parameter `help` which will
  36. output its available columns. For example:
  37. [source,js]
  38. --------------------------------------------------
  39. GET /_cat/master?help
  40. --------------------------------------------------
  41. // CONSOLE
  42. Might respond with:
  43. [source,txt]
  44. --------------------------------------------------
  45. id | | node id
  46. host | h | host name
  47. ip | | ip address
  48. node | n | node name
  49. --------------------------------------------------
  50. // TESTRESPONSE[s/[|]/[|]/ non_json]
  51. NOTE: `help` is not supported if any optional url parameter is used.
  52. For example `GET _cat/shards/twitter?help` or `GET _cat/indices/twi*?help`
  53. results in an error. Use `GET _cat/shards?help` or `GET _cat/indices?help`
  54. instead.
  55. [float]
  56. [[headers]]
  57. ==== Headers
  58. Each of the commands accepts a query string parameter `h` which forces
  59. only those columns to appear. For example:
  60. [source,js]
  61. --------------------------------------------------
  62. GET /_cat/nodes?h=ip,port,heapPercent,name
  63. --------------------------------------------------
  64. // CONSOLE
  65. Responds with:
  66. [source,txt]
  67. --------------------------------------------------
  68. 127.0.0.1 9300 27 sLBaIGK
  69. --------------------------------------------------
  70. // TESTRESPONSE[s/9300 27 sLBaIGK/\\d+ \\d+ .+/ non_json]
  71. You can also request multiple columns using simple wildcards like
  72. `/_cat/thread_pool?h=ip,queue*` to get all headers (or aliases) starting
  73. with `queue`.
  74. [float]
  75. [[numeric-formats]]
  76. ==== Numeric formats
  77. Many commands provide a few types of numeric output, either a byte, size
  78. or a time value. By default, these types are human-formatted,
  79. for example, `3.5mb` instead of `3763212`. The human values are not
  80. sortable numerically, so in order to operate on these values where
  81. order is important, you can change it.
  82. Say you want to find the largest index in your cluster (storage used
  83. by all the shards, not number of documents). The `/_cat/indices` API
  84. is ideal. We only need to tweak two things. First, we want to turn
  85. off human mode. We'll use a byte-level resolution. Then we'll pipe
  86. our output into `sort` using the appropriate column, which in this
  87. case is the eighth one.
  88. [source,sh]
  89. --------------------------------------------------
  90. % curl '192.168.56.10:9200/_cat/indices?bytes=b' | sort -rnk8
  91. green wiki2 3 0 10000 0 105274918 105274918
  92. green wiki1 3 0 10000 413 103776272 103776272
  93. green foo 1 0 227 0 2065131 2065131
  94. --------------------------------------------------
  95. // NOTCONSOLE
  96. If you want to change the <<time-units,time units>>, use `time` parameter.
  97. If you want to change the <<size-units,size units>>, use `size` parameter.
  98. If you want to change the <<byte-units,byte units>>, use `bytes` parameter.
  99. [float]
  100. ==== Response as text, json, smile, yaml or cbor
  101. [source,sh]
  102. --------------------------------------------------
  103. % curl 'localhost:9200/_cat/indices?format=json&pretty'
  104. [
  105. {
  106. "pri.store.size": "650b",
  107. "health": "yellow",
  108. "status": "open",
  109. "index": "twitter",
  110. "pri": "5",
  111. "rep": "1",
  112. "docs.count": "0",
  113. "docs.deleted": "0",
  114. "store.size": "650b"
  115. }
  116. ]
  117. --------------------------------------------------
  118. // NOTCONSOLE
  119. Currently supported formats (for the `?format=` parameter):
  120. - text (default)
  121. - json
  122. - smile
  123. - yaml
  124. - cbor
  125. Alternatively you can set the "Accept" HTTP header to the appropriate media format.
  126. All formats above are supported, the GET parameter takes precedence over the header.
  127. For example:
  128. [source,sh]
  129. --------------------------------------------------
  130. % curl '192.168.56.10:9200/_cat/indices?pretty' -H "Accept: application/json"
  131. [
  132. {
  133. "pri.store.size": "650b",
  134. "health": "yellow",
  135. "status": "open",
  136. "index": "twitter",
  137. "pri": "5",
  138. "rep": "1",
  139. "docs.count": "0",
  140. "docs.deleted": "0",
  141. "store.size": "650b"
  142. }
  143. ]
  144. --------------------------------------------------
  145. // NOTCONSOLE
  146. [float]
  147. [[sort]]
  148. ==== Sort
  149. Each of the commands accepts a query string parameter `s` which sorts the table by
  150. the columns specified as the parameter value. Columns are specified either by name or by
  151. alias, and are provided as a comma separated string. By default, sorting is done in
  152. ascending fashion. Appending `:desc` to a column will invert the ordering for
  153. that column. `:asc` is also accepted but exhibits the same behavior as the default sort order.
  154. For example, with a sort string `s=column1,column2:desc,column3`, the table will be
  155. sorted in ascending order by column1, in descending order by column2, and in ascending
  156. order by column3.
  157. [source,sh]
  158. --------------------------------------------------
  159. GET _cat/templates?v&s=order:desc,index_patterns
  160. --------------------------------------------------
  161. //CONSOLE
  162. returns:
  163. [source,txt]
  164. --------------------------------------------------
  165. name index_patterns order version
  166. pizza_pepperoni [*pepperoni*] 2
  167. sushi_california_roll [*avocado*] 1 1
  168. pizza_hawaiian [*pineapples*] 1
  169. --------------------------------------------------
  170. include::cat/alias.asciidoc[]
  171. include::cat/allocation.asciidoc[]
  172. include::cat/count.asciidoc[]
  173. include::cat/fielddata.asciidoc[]
  174. include::cat/health.asciidoc[]
  175. include::cat/indices.asciidoc[]
  176. include::cat/master.asciidoc[]
  177. include::cat/nodeattrs.asciidoc[]
  178. include::cat/nodes.asciidoc[]
  179. include::cat/pending_tasks.asciidoc[]
  180. include::cat/plugins.asciidoc[]
  181. include::cat/recovery.asciidoc[]
  182. include::cat/repositories.asciidoc[]
  183. include::cat/thread_pool.asciidoc[]
  184. include::cat/shards.asciidoc[]
  185. include::cat/segments.asciidoc[]
  186. include::cat/snapshots.asciidoc[]
  187. include::cat/templates.asciidoc[]