如何重命名集群中的索引? [英] how to rename an index in a cluster?

查看:149
本文介绍了如何重命名集群中的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重新命名一个集群中的几个索引(它们的名称必须被更改,我不能使用别名)。



我看到没有支持的方法来做,我发现最接近重命名索引目录,我在一个集群中尝试过这个。



集群有3台机器 A B C 并且每个碎片都复制碎片。我关闭了 A ,重命名为 / var / lib / elasticsearch / security / nodes / 0 / indexes / oldindexname / var / lib / elasticsearch / security / nodes / 0 / indexes / newindexname 并重新启动 A 。 >

集群的状态为黄色,弹性搜索正在做一些魔术来恢复正确的状态。过了一段时间,我结束了




  • oldindexname 可用并完全复制从 B C 我猜)

  • newindexname 可用(我可以搜索),但是头插件显示它的分片处于未分配状态,并且它们显示为灰色(未复制)



在恢复期间 security.log 显示以下消息:



[pre> [2015-02-20 11:02:33,461] [INFO] [gateway.local.state.meta] [A.example.com]悬挂的索引目录名是[newindexname ],状态名是[oldindexname],重命名为目录名

虽然 newindexname 可以搜索,肯定不是正常状态。



通过删除 newindexname,我回滚到以前的状态。集群回到绿色,没有任何未分配条目。



鉴于此,我如何将 oldindexname 重命名为



注意:我想到的最终解决方案是将 oldindex 滚动复制到 newindex 中,然后删除 oldindex 。这将需要时间,所以如果有更直接的解决方案将是巨大的。

解决方案

你可以使用 REINDEX 来做到这一点。


Reindex不会尝试设置目标索引。它不
复制源索引的设置。您应该设置
目标索引
在运行_reindex操作之前,包括
设置映射,分片计数,副本等。





  1. 首先将索引复制到新名称



  POST / _reindex 
{
source:{
index:twitter
},
dest:{
index:new_twitter
}
}




  1. 现在删除索引



  DELETE / twitter 


I need to rename several indexes in a cluster (their name must be changed, I cannot use aliases).

I saw that there are no supported ways to do that, the closest I found is to rename the directory of the index, I tried this in a cluster.

The cluster has 3 machines A, B and C and the shards are replicated on each of them. I shut down elasticsearch on A, renamed /var/lib/elasticsearch/security/nodes/0/indices/oldindexname to /var/lib/elasticsearch/security/nodes/0/indices/newindexname and restarted A.

The state of the cluster was yellow and elasticsearch was doing some magic to restore a correct state. After some time I ended up with

  • oldindexname being available and fully replicated (recovered from B and C I guess)
  • newindexname being available (I can search it) but the head plugin shows that its shards are in an "Unassigned" state and that they are grayed out (not replicated)

During the recovery security.log showed the following message:

[2015-02-20 11:02:33,461][INFO ][gateway.local.state.meta ] [A.example.com] dangled index directory name is [newindexname], state name is [oldindexname], renaming to directory name

While newindexname is searchable, it is certainly not in a normal state.

I rolled back to the previous state by deleting newindexname. The cluster is back to green without any "Unassigned" entries.

Given that, how can I rename oldindexname to newindexname in a cluster?

Note: the ultimate solution I have in mind is to scroll-copy oldindex into newindex and delete oldindex afterwards. This is going to take time so if there is a more direct solution it would be great.

解决方案

You can use REINDEX to do that.

Reindex does not attempt to set up the destination index. It does not copy the settings of the source index. You should set up the destination index prior to running a _reindex action, including setting up mappings, shard counts, replicas, etc.

  1. First copy the index to a new name

POST /_reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}

  1. Now delete the Index

DELETE /twitter

这篇关于如何重命名集群中的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆