简体   繁体   English

如何删除 ElasticSearch 索引的特定分片

[英]How to delete a specific shard of an ElasticSearch index

I recently had a SNAFU cause my cluster to end up with split-brain (despite having many controls in place) resulting in shards that are basically busted.我最近有一个 SNAFU 导致我的集群最终出现裂脑(尽管有很多控制)导致分片基本上被破坏。 I've got all the nodes back in play properly, recognizing the right master, etc. but the cluster remains red and rightfully so;我已经让所有节点正常恢复运行,识别正确的主节点等,但集群仍然是红色的,这是理所当然的; there are a few shards that have no home.有一些碎片没有家。

After using my RubberBand script , I was able to explore using VisualJSON to find shards like the following one, that have no node:使用我的RubberBand 脚本后,我能够使用VisualJSON进行探索,以找到如下所示的没有节点的分片:

{
    "index": "logstash-2013.12.27",
    "node": null,
    "primary": false,
    "relocating_node": null,
    "shard": 4,
    "state": "UNASSIGNED"
},

I would like to delete them but I can't seem to find an API call to delete a shard, only deleting whole indices or using queries.我想删除它们,但似乎找不到删除分片的 API 调用,只能删除整个索引或使用查询。 Thanks in advance!提前致谢!

This command will take an orphaned shard and assign it to node efsKb4DzQ2iaIfKfu36vsA .此命令将采用孤立的分片并将其分配给节点efsKb4DzQ2iaIfKfu36vsA

curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
  "commands": [
    {
      "allocate": {
        "index": "tweedle-2013.12.21",
        "shard": 3,
        "node": "efsKb4DzQ2iaIfKfu36vsA",
        "allow_primary": true
      }
    }
  ]
}'

You can't delete an unassigned shard because there is no shard to be deleted.您无法删除未分配的分片,因为没有要删除的分片。 An unassigned shard is not a corrupted shard, but a missing replica .未分配的分片不是损坏的分片,而是丢失的副本

Your config probably tells ES (ElasticSearch) to create replicas and assign them on different nodes for high availability and/or fault tolerance.您的配置可能会告诉 ES (ElasticSearch) 创建副本并将它们分配到不同的节点上以实现高可用性和/或容错。 ES was not able to automatically create and assign a replica and, thus, you see the UNASSIGNED state. ES 无法自动创建和分配副本,因此您会看到UNASSIGNED状态。 It could have been due to a network error, memory not available, etc.这可能是由于网络错误、内存不可用等。

You may want to find the reason why the allocation failed:您可能想找出分配失败的原因:

curl -XPOST 'localhost:9200/_cluster/allocation/explain?pretty'

And, then, ask ES to retry the allocation for you :然后,让 ES 为您重试分配

curl -XPOST 'localhost:9200/_cluster/reroute?retry_failed'

Credits to ES's expert answer which says归功于 ES 的专家回答,其中说

After 5 unsuccessful allocation attempts, the master gives up and needs manual triggering to give it another allocation attempt在 5 次分配尝试失败后,master 放弃并需要手动触发再给它一次分配尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM