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

Spa*_*nky 3 sharding elasticsearch

我最近有一个SNAFU导致我的集群最终出现裂脑(尽管有许多控制措施)导致碎片基本上被破坏.我已经让所有节点恢复正常,识别正确的主人等等,但是群集仍然是红色的,这是正确的; 有一些没有家的碎片.

在使用我的RubberBand脚本之后,我能够使用VisualJSON来查找像以下那样没有节点的分片:

{
    "index": "logstash-2013.12.27",
    "node": null,
    "primary": false,
    "relocating_node": null,
    "shard": 4,
    "state": "UNASSIGNED"
},
Run Code Online (Sandbox Code Playgroud)

我想删除它们,但我似乎无法找到删除分片的API调用,只删除整个索引或使用查询.提前致谢!

Spa*_*nky 7

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

此命令将采用孤立的分片并将其分配给节点 efsKb4DzQ2iaIfKfu36vsA

在一条线上:

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


Ric*_*rdo 5

您无法删除未分配的分片,因为没有要删除的分片。未分配的分片不是损坏的分片,而是 丢失的副本

您的配置可能会告诉 ES (ElasticSearch) 创建副本并将它们分配到不同的节点上,以实现高可用性和/或容错。ES 无法自动创建和分配副本,因此您可以看到状态UNASSIGNED。可能是由于网络错误、内存不可用等原因。

您可能想查找分配失败的原因:

curl -XPOST 'localhost:9200/_cluster/allocation/explain?pretty'
Run Code Online (Sandbox Code Playgroud)

然后,让 ES为您重试分配

curl -XPOST 'localhost:9200/_cluster/reroute?retry_failed'
Run Code Online (Sandbox Code Playgroud)

感谢 ES 的专家回答,其中说

5 次分配尝试失败后,master 放弃并需要手动触发以进行另一次分配尝试