shards.asciidoc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [[cat-shards]]
  2. === cat shards
  3. The `shards` command is the detailed view of what nodes contain which
  4. shards. It will tell you if it's a primary or replica, the number of
  5. docs, the bytes it takes on disk, and the node where it's located.
  6. Here we see a single index, with one primary shard and no replicas:
  7. [source,js]
  8. ---------------------------------------------------------------------------
  9. GET _cat/shards
  10. ---------------------------------------------------------------------------
  11. // CONSOLE
  12. // TEST[setup:twitter]
  13. This will return
  14. [source,txt]
  15. ---------------------------------------------------------------------------
  16. twitter 0 p STARTED 3014 31.1mb 192.168.56.10 H5dfFeA
  17. ---------------------------------------------------------------------------
  18. // TESTRESPONSE[s/3014/\\d+/]
  19. // TESTRESPONSE[s/31.1mb/\\d+(\.\\d+)?[kmg]?b/]
  20. // TESTRESPONSE[s/192.168.56.10/.*/]
  21. // TESTRESPONSE[s/H5dfFeA/node-0/ non_json]
  22. [float]
  23. [[index-pattern]]
  24. ==== Index pattern
  25. If you have many shards, you may wish to limit which indices show up
  26. in the output. You can always do this with `grep`, but you can save
  27. some bandwidth by supplying an index pattern to the end.
  28. [source,js]
  29. ---------------------------------------------------------------------------
  30. GET _cat/shards/twitt*
  31. ---------------------------------------------------------------------------
  32. // CONSOLE
  33. // TEST[setup:twitter]
  34. Which will return the following
  35. [source,txt]
  36. ---------------------------------------------------------------------------
  37. twitter 0 p STARTED 3014 31.1mb 192.168.56.10 H5dfFeA
  38. ---------------------------------------------------------------------------
  39. // TESTRESPONSE[s/3014/\\d+/]
  40. // TESTRESPONSE[s/31.1mb/\\d+(\.\\d+)?[kmg]?b/]
  41. // TESTRESPONSE[s/192.168.56.10/.*/]
  42. // TESTRESPONSE[s/H5dfFeA/node-0/ non_json]
  43. [float]
  44. [[relocation]]
  45. ==== Relocation
  46. Let's say you've checked your health and you see relocating
  47. shards. Where are they from and where are they going?
  48. [source,js]
  49. ---------------------------------------------------------------------------
  50. GET _cat/shards
  51. ---------------------------------------------------------------------------
  52. // CONSOLE
  53. // TEST[skip:for now, relocation cannot be recreated]
  54. A relocating shard will be shown as follows
  55. [source,txt]
  56. ---------------------------------------------------------------------------
  57. twitter 0 p RELOCATING 3014 31.1mb 192.168.56.10 H5dfFeA -> -> 192.168.56.30 bGG90GE
  58. ---------------------------------------------------------------------------
  59. // TESTRESPONSE[non_json]
  60. [float]
  61. [[states]]
  62. ==== Shard states
  63. Before a shard can be used, it goes through an `INITIALIZING` state.
  64. `shards` can show you which ones.
  65. [source,js]
  66. ---------------------------------------------------------------------------
  67. GET _cat/shards
  68. ---------------------------------------------------------------------------
  69. // CONSOLE
  70. // TEST[skip:there is no guarantee to test for shards in initializing state]
  71. You can get the initializing state in the response like this
  72. [source,txt]
  73. ---------------------------------------------------------------------------
  74. twitter 0 p STARTED 3014 31.1mb 192.168.56.10 H5dfFeA
  75. twitter 0 r INITIALIZING 0 14.3mb 192.168.56.30 bGG90GE
  76. ---------------------------------------------------------------------------
  77. // TESTRESPONSE[non_json]
  78. If a shard cannot be assigned, for example you've overallocated the
  79. number of replicas for the number of nodes in the cluster, the shard
  80. will remain `UNASSIGNED` with the <<reason-unassigned,reason code>> `ALLOCATION_FAILED`.
  81. You can use the shards API to find out that reason.
  82. [source,js]
  83. ---------------------------------------------------------------------------
  84. GET _cat/shards?h=index,shard,prirep,state,unassigned.reason
  85. ---------------------------------------------------------------------------
  86. // CONSOLE
  87. // TEST[skip:for now]
  88. The reason for an unassigned shard will be listed as the last field
  89. [source,txt]
  90. ---------------------------------------------------------------------------
  91. twitter 0 p STARTED 3014 31.1mb 192.168.56.10 H5dfFeA
  92. twitter 0 r STARTED 3014 31.1mb 192.168.56.30 bGG90GE
  93. twitter 0 r STARTED 3014 31.1mb 192.168.56.20 I8hydUG
  94. twitter 0 r UNASSIGNED ALLOCATION_FAILED
  95. ---------------------------------------------------------------------------
  96. // TESTRESPONSE[non_json]
  97. [float]
  98. [[reason-unassigned]]
  99. ==== Reasons for unassigned shard
  100. These are the possible reasons for a shard to be in a unassigned state:
  101. [horizontal]
  102. `INDEX_CREATED`:: Unassigned as a result of an API creation of an index.
  103. `CLUSTER_RECOVERED`:: Unassigned as a result of a full cluster recovery.
  104. `INDEX_REOPENED`:: Unassigned as a result of opening a closed index.
  105. `DANGLING_INDEX_IMPORTED`:: Unassigned as a result of importing a dangling index.
  106. `NEW_INDEX_RESTORED`:: Unassigned as a result of restoring into a new index.
  107. `EXISTING_INDEX_RESTORED`:: Unassigned as a result of restoring into a closed index.
  108. `REPLICA_ADDED`:: Unassigned as a result of explicit addition of a replica.
  109. `ALLOCATION_FAILED`:: Unassigned as a result of a failed allocation of the shard.
  110. `NODE_LEFT`:: Unassigned as a result of the node hosting it leaving the cluster.
  111. `REROUTE_CANCELLED`:: Unassigned as a result of explicit cancel reroute command.
  112. `REINITIALIZED`:: When a shard moves from started back to initializing, for example, with shadow replicas.
  113. `REALLOCATED_REPLICA`:: A better replica location is identified and causes the existing replica allocation to be cancelled.