cat.asciidoc 6.4 KB

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