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