shard-tool.asciidoc 3.7 KB

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