cat.asciidoc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. You only need to add three things to the API request:
  82. . The `bytes` query string parameter with a value of `b` to get byte-level resolution.
  83. . The `s` (sort) parameter with a value of `store.size:desc` to sort the output
  84. by shard storage in descending order.
  85. . The `v` (verbose) parameter to include column headings in the response.
  86. [source,console]
  87. --------------------------------------------------
  88. GET /_cat/indices?bytes=b&s=store.size:desc&v
  89. --------------------------------------------------
  90. // TEST[setup:huge_twitter]
  91. // TEST[s/^/PUT twitter2\n{"settings": {"number_of_replicas": 0}}\n/]
  92. The API returns the following response:
  93. [source,txt]
  94. --------------------------------------------------
  95. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  96. yellow open twitter u8FNjxh8Rfy_awN11oDKYQ 1 1 1200 0 72171 72171
  97. green open twitter2 nYFWZEO7TUiOjLQXBaYJpA 1 0 0 0 230 230
  98. --------------------------------------------------
  99. // TESTRESPONSE[s/72171|230/\\d+/]
  100. // TESTRESPONSE[s/u8FNjxh8Rfy_awN11oDKYQ|nYFWZEO7TUiOjLQXBaYJpA/.+/ non_json]
  101. If you want to change the <<time-units,time units>>, use `time` parameter.
  102. If you want to change the <<size-units,size units>>, use `size` parameter.
  103. If you want to change the <<byte-units,byte units>>, use `bytes` parameter.
  104. [float]
  105. ==== Response as text, json, smile, yaml or cbor
  106. [source,sh]
  107. --------------------------------------------------
  108. % curl 'localhost:9200/_cat/indices?format=json&pretty'
  109. [
  110. {
  111. "pri.store.size": "650b",
  112. "health": "yellow",
  113. "status": "open",
  114. "index": "twitter",
  115. "pri": "5",
  116. "rep": "1",
  117. "docs.count": "0",
  118. "docs.deleted": "0",
  119. "store.size": "650b"
  120. }
  121. ]
  122. --------------------------------------------------
  123. // NOTCONSOLE
  124. Currently supported formats (for the `?format=` parameter):
  125. - text (default)
  126. - json
  127. - smile
  128. - yaml
  129. - cbor
  130. Alternatively you can set the "Accept" HTTP header to the appropriate media format.
  131. All formats above are supported, the GET parameter takes precedence over the header.
  132. For example:
  133. [source,sh]
  134. --------------------------------------------------
  135. % curl '192.168.56.10:9200/_cat/indices?pretty' -H "Accept: application/json"
  136. [
  137. {
  138. "pri.store.size": "650b",
  139. "health": "yellow",
  140. "status": "open",
  141. "index": "twitter",
  142. "pri": "5",
  143. "rep": "1",
  144. "docs.count": "0",
  145. "docs.deleted": "0",
  146. "store.size": "650b"
  147. }
  148. ]
  149. --------------------------------------------------
  150. // NOTCONSOLE
  151. [float]
  152. [[sort]]
  153. ==== Sort
  154. Each of the commands accepts a query string parameter `s` which sorts the table by
  155. the columns specified as the parameter value. Columns are specified either by name or by
  156. alias, and are provided as a comma separated string. By default, sorting is done in
  157. ascending fashion. Appending `:desc` to a column will invert the ordering for
  158. that column. `:asc` is also accepted but exhibits the same behavior as the default sort order.
  159. For example, with a sort string `s=column1,column2:desc,column3`, the table will be
  160. sorted in ascending order by column1, in descending order by column2, and in ascending
  161. order by column3.
  162. [source,sh]
  163. --------------------------------------------------
  164. GET _cat/templates?v&s=order:desc,index_patterns
  165. --------------------------------------------------
  166. //CONSOLE
  167. returns:
  168. [source,txt]
  169. --------------------------------------------------
  170. name index_patterns order version
  171. pizza_pepperoni [*pepperoni*] 2
  172. sushi_california_roll [*avocado*] 1 1
  173. pizza_hawaiian [*pineapples*] 1
  174. --------------------------------------------------
  175. include::cat/alias.asciidoc[]
  176. include::cat/allocation.asciidoc[]
  177. include::cat/count.asciidoc[]
  178. include::cat/fielddata.asciidoc[]
  179. include::cat/health.asciidoc[]
  180. include::cat/indices.asciidoc[]
  181. include::cat/master.asciidoc[]
  182. include::cat/nodeattrs.asciidoc[]
  183. include::cat/nodes.asciidoc[]
  184. include::cat/pending_tasks.asciidoc[]
  185. include::cat/plugins.asciidoc[]
  186. include::cat/recovery.asciidoc[]
  187. include::cat/repositories.asciidoc[]
  188. include::cat/tasks.asciidoc[]
  189. include::cat/thread_pool.asciidoc[]
  190. include::cat/shards.asciidoc[]
  191. include::cat/segments.asciidoc[]
  192. include::cat/snapshots.asciidoc[]
  193. include::cat/templates.asciidoc[]