segments.asciidoc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. [[indices-segments]]
  2. === Index segments API
  3. ++++
  4. <titleabbrev>Index segments</titleabbrev>
  5. ++++
  6. Returns low-level information about the https://lucene.apache.org/core/[Lucene]
  7. segments in index shards. For data streams, the API returns information about
  8. the stream's backing indices.
  9. [source,console]
  10. ----
  11. GET /my-index-000001/_segments
  12. ----
  13. // TEST[setup:my_index]
  14. [[index-segments-api-request]]
  15. ==== {api-request-title}
  16. `GET /<target>/_segments`
  17. `GET /_segments`
  18. [[index-segments-api-prereqs]]
  19. ==== {api-prereq-title}
  20. * If the {es} {security-features} are enabled, you must have the `monitor` or
  21. `manage` <<privileges-list-indices,index privilege>> for the target data stream,
  22. index, or index alias.
  23. [[index-segments-api-path-params]]
  24. ==== {api-path-parms-title}
  25. `<target>`::
  26. (Optional, string)
  27. Comma-separated list of data streams, indices, and index aliases used to limit
  28. the request. Wildcard expressions (`*`) are supported.
  29. +
  30. To target all data streams and indices in a cluster, omit this parameter or use
  31. `_all` or `*`.
  32. [[index-segments-api-query-params]]
  33. ==== {api-query-parms-title}
  34. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  35. +
  36. Defaults to `true`.
  37. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  38. +
  39. Defaults to `open`.
  40. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  41. `verbose`::
  42. experimental:[]
  43. (Optional, Boolean)
  44. If `true`, the response includes detailed information
  45. about Lucene's memory usage.
  46. Defaults to `false`.
  47. [[index-segments-api-response-body]]
  48. ==== {api-response-body-title}
  49. `<segment>`::
  50. (String)
  51. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=segment]
  52. `generation`::
  53. (Integer)
  54. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=generation]
  55. `num_docs`::
  56. (Integer)
  57. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=docs-count]
  58. `deleted_docs`::
  59. (Integer)
  60. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=docs-deleted]
  61. `size_in_bytes`::
  62. (Integer)
  63. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=segment-size]
  64. `memory_in_bytes`::
  65. (Integer)
  66. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=memory]
  67. `committed`::
  68. (Boolean)
  69. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=committed]
  70. `search`::
  71. (Boolean)
  72. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=segment-search]
  73. `version`::
  74. (String)
  75. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=segment-version]
  76. `compound`::
  77. (Boolean)
  78. If `true`, Lucene merged all files from the segment
  79. into a single file to save file descriptors.
  80. `attributes`::
  81. (Object)
  82. Contains information about whether high compression was enabled.
  83. [[index-segments-api-example]]
  84. ==== {api-examples-title}
  85. ===== Get segment information for a specific data stream or index
  86. [source,console]
  87. --------------------------------------------------
  88. GET /test/_segments
  89. --------------------------------------------------
  90. // TEST[s/^/PUT test\n{"settings":{"number_of_shards":1, "number_of_replicas": 0}}\nPOST test\/_doc\?refresh\n{"test": "test"}\n/]
  91. ===== Get segment information for several data streams and indices
  92. [source,console]
  93. --------------------------------------------------
  94. GET /test1,test2/_segments
  95. --------------------------------------------------
  96. // TEST[s/^/PUT test1\nPUT test2\n/]
  97. ===== Get segment information for all data streams and indices in a cluster
  98. [source,console]
  99. --------------------------------------------------
  100. GET /_segments
  101. --------------------------------------------------
  102. // TEST[s/^/PUT test\n{"settings":{"number_of_shards":1, "number_of_replicas": 0}}\nPOST test\/_doc\?refresh\n{"test": "test"}\n/]
  103. The API returns the following response:
  104. [source,console-response]
  105. --------------------------------------------------
  106. {
  107. "_shards": ...
  108. "indices": {
  109. "test": {
  110. "shards": {
  111. "0": [
  112. {
  113. "routing": {
  114. "state": "STARTED",
  115. "primary": true,
  116. "node": "zDC_RorJQCao9xf9pg3Fvw"
  117. },
  118. "num_committed_segments": 0,
  119. "num_search_segments": 1,
  120. "segments": {
  121. "_0": {
  122. "generation": 0,
  123. "num_docs": 1,
  124. "deleted_docs": 0,
  125. "size_in_bytes": 3800,
  126. "memory_in_bytes": 1410,
  127. "committed": false,
  128. "search": true,
  129. "version": "7.0.0",
  130. "compound": true,
  131. "attributes": {
  132. }
  133. }
  134. }
  135. }
  136. ]
  137. }
  138. }
  139. }
  140. }
  141. --------------------------------------------------
  142. // TESTRESPONSE[s/"_shards": \.\.\./"_shards": $body._shards,/]
  143. // TESTRESPONSE[s/"node": "zDC_RorJQCao9xf9pg3Fvw"/"node": $body.$_path/]
  144. // TESTRESPONSE[s/"attributes": \{[^}]*\}/"attributes": $body.$_path/]
  145. // TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/]
  146. // TESTRESPONSE[s/7\.0\.0/$body.$_path/]
  147. ===== Verbose mode
  148. To add additional information that can be used for debugging,
  149. use the `verbose` flag.
  150. experimental::[]
  151. [source,console]
  152. --------------------------------------------------
  153. GET /test/_segments?verbose=true
  154. --------------------------------------------------
  155. // TEST[continued]
  156. The API returns the following response:
  157. [source,console-response]
  158. --------------------------------------------------
  159. {
  160. ...
  161. "_0": {
  162. ...
  163. "ram_tree": [
  164. {
  165. "description": "postings [PerFieldPostings(format=1)]",
  166. "size_in_bytes": 2696,
  167. "children": [
  168. {
  169. "description": "format 'Lucene50_0' ...",
  170. "size_in_bytes": 2608,
  171. "children" :[ ... ]
  172. },
  173. ...
  174. ]
  175. },
  176. ...
  177. ]
  178. }
  179. ...
  180. }
  181. --------------------------------------------------
  182. // TESTRESPONSE[skip:Response is too verbose to be fully shown in documentation, so we just show the relevant bit and don't test the response.]