首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何重命名集群中的索引?

如何重命名集群中的索引?
EN

Stack Overflow用户
提问于 2015-02-20 18:32:22
回答 8查看 145.4K关注 0票数 140

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

我发现没有支持这样做的方法,我找到的最接近rename the directory of the index的方法,我在集群中尝试过。

集群有3台机器ABC,并在每台机器上复制分片。我关闭了A上的elasticsearch,将/var/lib/elasticsearch/security/nodes/0/indices/oldindexname重命名为/var/lib/elasticsearch/security/nodes/0/indices/newindexname,然后重启了A

集群的状态是黄色的,elasticsearch正在做一些魔法来恢复正确的状态。一段时间后,我最终得到了

  • oldindexname可用且完全复制(我猜是从BC恢复的)
  • newindexname可用(我可以搜索它)但是head插件显示它的分片处于“未分配”状态,并且它们是灰色的(未复制)

在恢复过程中,security.log显示以下消息:

代码语言:javascript
运行
复制
[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

虽然newindexname是可搜索的,但它肯定不处于正常状态。

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

鉴于此,如何在集群中将oldindexname重命名为newindexname

注意:我考虑的最终解决方案是滚动复制oldindexnewindex中,然后删除oldindex。这将需要时间,所以如果有更直接的解决方案,那就太好了。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2019-12-19 02:00:25

从ElasticSearch 7.4开始,重命名索引的最佳方法是使用新引入的Clone Index API复制索引,然后使用Delete Index API删除原始索引。

与出于相同目的使用Snapshot API或Reindex API相比,Clone index API的主要优势是速度,因为Clone Index API将段从源索引硬链接到目标索引,而无需重新处理其任何内容(显然,在支持硬链接的文件系统上;否则,在文件系统级别复制文件,这仍然比其他方法更有效)。克隆索引还保证目标索引在每个点都与源索引相同(也就是说,不需要手动复制设置和映射,这与重新编制索引的方法相反),并且不需要配置本地快照目录。

旁注:尽管此过程比以前的解决方案快得多,但它仍然意味着停机时间。有一些实际的用例可以证明重命名索引是合理的(例如,作为拆分、收缩或备份工作流中的一个步骤),但是重命名索引不应该是日常操作的一部分。如果您的工作流需要频繁地重命名索引,那么您应该考虑改用。

以下是将索引source_index重命名为target_index的完整操作序列的示例。它可以使用一些特定于ElasticSearch的控制台来执行,比如集成的in Kibana。有关此示例的替代版本,请参阅this gist,使用curl而不是弹性搜索控制台。

代码语言:javascript
运行
复制
# Make sure the source index is actually open
POST /source_index/_open

# Put the source index in read-only mode
PUT /source_index/_settings
{
  "settings": {
    "index.blocks.write": "true"
  }
}

# Clone the source index to the target name, and set the target to read-write mode
POST /source_index/_clone/target_index
{
  "settings": {
    "index.blocks.write": null 
  }
}

# Wait until the target index is green;
# it should usually be fast (assuming your filesystem supports hard links).
GET /_cluster/health/target_index?wait_for_status=green&timeout=30s

# If it appears to be taking too much time for the cluster to get back to green,
# the following requests might help you identify eventual outstanding issues (if any)
GET /_cat/indices/target_index
GET /_cat/recovery/target_index
GET /_cluster/allocation/explain

# Delete the source index
DELETE /source_index
票数 63
EN

Stack Overflow用户

发布于 2016-06-28 21:49:06

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

重新索引不会尝试设置目标索引。它不复制源索引的设置。您应该在运行_reindex操作之前执行set up the destination index,包括设置映射、分片计数、副本等。

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

代码语言:javascript
运行
复制
POST /_reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}

  1. 现在删除索引

代码语言:javascript
运行
复制
DELETE /twitter
票数 187
EN

Stack Overflow用户

发布于 2016-02-24 13:00:13

要重命名索引,您可以使用Elasticsearch Snapshot模块。

首先,您必须为您的index.while拍摄快照,恢复它,您可以重命名您的索引。

代码语言:javascript
运行
复制
    POST /_snapshot/my_backup/snapshot_1/_restore
    {
     "indices": "jal",
     "ignore_unavailable": "true",
     "include_global_state": false,
     "rename_pattern": "jal",
     "rename_replacement": "jal1"
     }

rename_replacement:-要在其中备份数据的新索引名称。

票数 63
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28626803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档