shard-tool.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. [[shard-tool]]
  2. == elasticsearch-shard
  3. In some cases the Lucene index or translog of a shard copy can become corrupted.
  4. The `elasticsearch-shard` command enables you to remove corrupted parts of the
  5. shard if a good copy of the shard cannot be recovered automatically or restored
  6. from backup.
  7. [WARNING]
  8. You will lose the corrupted data when you run `elasticsearch-shard`. This tool
  9. should only be used as a last resort if there is no way to recover from another
  10. copy of the shard or restore a snapshot.
  11. [discrete]
  12. === Synopsis
  13. [source,shell]
  14. --------------------------------------------------
  15. bin/elasticsearch-shard remove-corrupted-data
  16. ([--index <Index>] [--shard-id <ShardId>] | [--dir <IndexPath>])
  17. [--truncate-clean-translog]
  18. [-E <KeyValuePair>]
  19. [-h, --help] ([-s, --silent] | [-v, --verbose])
  20. --------------------------------------------------
  21. [discrete]
  22. === Description
  23. When {es} detects that a shard's data is corrupted, it fails that shard copy and
  24. refuses to use it. Under normal conditions, the shard is automatically recovered
  25. from another copy. If no good copy of the shard is available and you cannot
  26. restore one from a snapshot, you can use `elasticsearch-shard` to remove the
  27. corrupted data and restore access to any remaining data in unaffected segments.
  28. [WARNING]
  29. Stop Elasticsearch before running `elasticsearch-shard`.
  30. To remove corrupted shard data use the `remove-corrupted-data` subcommand.
  31. There are two ways to specify the path:
  32. * Specify the index name and shard name with the `--index` and `--shard-id`
  33. options.
  34. * Use the `--dir` option to specify the full path to the corrupted index or
  35. translog files.
  36. [discrete]
  37. ==== Removing corrupted data
  38. `elasticsearch-shard` analyses the shard copy and provides an overview of the
  39. corruption found. To proceed you must then confirm that you want to remove the
  40. corrupted data.
  41. [WARNING]
  42. Back up your data before running `elasticsearch-shard`. This is a destructive
  43. operation that removes corrupted data from the shard.
  44. [source,txt]
  45. --------------------------------------------------
  46. $ bin/elasticsearch-shard remove-corrupted-data --index my-index-000001 --shard-id 0
  47. WARNING: Elasticsearch MUST be stopped before running this tool.
  48. Please make a complete backup of your index before using this tool.
  49. Opening Lucene index at /var/lib/elasticsearchdata/indices/P45vf_YQRhqjfwLMUvSqDw/0/index/
  50. >> Lucene index is corrupted at /var/lib/elasticsearchdata/indices/P45vf_YQRhqjfwLMUvSqDw/0/index/
  51. Opening translog at /var/lib/elasticsearchdata/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/
  52. >> Translog is clean at /var/lib/elasticsearchdata/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/
  53. Corrupted Lucene index segments found - 32 documents will be lost.
  54. WARNING: YOU WILL LOSE DATA.
  55. Continue and remove docs from the index ? Y
  56. WARNING: 1 broken segments (containing 32 documents) detected
  57. Took 0.056 sec total.
  58. Writing...
  59. OK
  60. Wrote new segments file "segments_c"
  61. Marking index with the new history uuid : 0pIBd9VTSOeMfzYT6p0AsA
  62. Changing allocation id V8QXk-QXSZinZMT-NvEq4w to tjm9Ve6uTBewVFAlfUMWjA
  63. You should run the following command to allocate this shard:
  64. POST /_cluster/reroute
  65. {
  66. "commands" : [
  67. {
  68. "allocate_stale_primary" : {
  69. "index" : "index42",
  70. "shard" : 0,
  71. "node" : "II47uXW2QvqzHBnMcl2o_Q",
  72. "accept_data_loss" : false
  73. }
  74. }
  75. ]
  76. }
  77. You must accept the possibility of data loss by changing the `accept_data_loss` parameter to `true`.
  78. Deleted corrupt marker corrupted_FzTSBSuxT7i3Tls_TgwEag from /var/lib/elasticsearchdata/indices/P45vf_YQRhqjfwLMUvSqDw/0/index/
  79. --------------------------------------------------
  80. When you use `elasticsearch-shard` to drop the corrupted data, the shard's
  81. allocation ID changes. After restarting the node, you must use the
  82. <<cluster-reroute,cluster reroute API>> to tell Elasticsearch to use the new ID.
  83. The `elasticsearch-shard` command shows the request that you need to submit.
  84. You can also use the `-h` option to get a list of all options and parameters
  85. that the `elasticsearch-shard` tool supports.
  86. Finally, you can use the `--truncate-clean-translog` option to truncate the
  87. shard's translog even if it does not appear to be corrupt.