segments.asciidoc 5.8 KB

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