栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

重命名和删除Elasticsearch索引

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

重命名和删除Elasticsearch索引

我建议在可能创建增量不同版本的索引的方案中始终使用别名,例如在搜索策略中优化信号模型时可能就是这种情况。

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

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 repeatableforeach (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 operablevar clusterHealthResponse = client.ClusterHealth(c => c    .WaitForStatus(WaitForStatus.Yellow)    .Index(indices[1]));// swap the aliasvar 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-v2var aliasResponse = client.GetAlias(a => a.Name(alias));

最后一个响应的输出是

{  "index-v2" : {    "aliases" : {      "index-alias" : { }    }  }}

搜索时,使用者将始终使用别名。由于别名仅指向单个索引,因此您也可以使用别名为新文档建立索引并更新现有文档。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379892.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号