cat.asciidoc 6.6 KB

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