es index 改名_重命名和删除Elasticsearch索引

在建议您创建索引的增量不同版本的情况下,我会建议始终使用

using aliases,这可能是在搜索策略中优化信号模型时的情况.

您可以在创建索引时添加别名

var client = new ElasticClient(connectionSettings);

var indices = new[] { "index-v1", "index-v2" };

var alias = "index-alias";

// delete index-v1 and index-v2 if they exist, to

// allow this example to be repeatable

foreach (var index in indices)

{

if (client.IndexExists(index).Exists)

{

client.DeleteIndex(index);

}

}

var createIndexResponse = client.CreateIndex(indices[0], c => c

.Aliases(a => a

.Alias(alias)

)

);

然后,当您创建新索引时,可以从当前索引中删除别名并将其添加到新索引.别名交换操作是原子的

createIndexResponse = client.CreateIndex(indices[1]);

// wait for index-v2 to be operable

var clusterHealthResponse = client.ClusterHealth(c => c

.WaitForStatus(WaitForStatus.Yellow)

.Index(indices[1]));

// swap the alias

var bulkAliasResponse = client.Alias(ba => ba

.Add(add => add.Alias(alias).Index(indices[1]))

.Remove(remove => remove.Alias(alias).Index("*"))

);

// verify that the alias only exists on index-v2

var aliasResponse = client.GetAlias(a => a.Name(alias));

最后一个响应的输出是

{

"index-v2" : {

"aliases" : {

"index-alias" : { }

}

}

}

在搜索时,消费者总是会使用别名.由于别名仅指向单个索引,因此您还可以使用它来索引新文档并更新现有文档.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值