elasticsearch - 使用Nest 7.x重新创建ElasticSearch索引

标签 elasticsearch nest

我希望能够在生产中重新创建ElasticSearch索引,而不会造成任何停机。

使用Nest的早期版本(5及更早版本),可以通过使用指向原始索引的别名,创建新索引,将别名更新为指向新索引,然后删除原始索引来实现。

Nest 7.x是否可以在不停机的情况下实现类似的目标?如果是这样,如何。如果您可以提供一个带有Object Initializer Syntax的示例,那将是最有帮助的。

最佳答案

请在下面找到带有注释的示例

//first we create base index
var createIndexResponse = await client.Indices.CreateAsync("index1");

//and we create alias to it
var putAliasResponse = await client.Indices.PutAliasAsync(new PutAliasRequest("index1", "index"));

//next step is to create a new index
var createIndexResponse2 = await client.Indices.CreateAsync("index2");

//and create bulk operation to remove alias to index1 and create alias to index2
await client.Indices.BulkAliasAsync(new BulkAliasRequest
{
    Actions = new List<IAliasAction>
    {
        new AliasRemoveAction {Remove = new AliasRemoveOperation {Index = "index1", Alias = "index"}},
        new AliasAddAction {Add = new AliasAddOperation {Index = "index2", Alias = "index"}}
    }
});

System.Console.WriteLine("Indices pointing to alias:");
foreach (var index in await client.GetIndicesPointingToAliasAsync("index"))
{
    System.Console.WriteLine(index);
}

输出:
Indices pointing to alias:
index2

希望能有所帮助。

关于elasticsearch - 使用Nest 7.x重新创建ElasticSearch索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59929255/

相关文章:

python - Django Haystack搜索html标签会返回所有帖子

Elasticsearch 许可证.过期.功能安全状态 403

elasticsearch - Kibana 垂直条形图在 X 轴的哪个位置我有值总和的桶?

elasticsearch - 从 OpenDistro docker 镜像运行时为 "Kibana server is not ready yet"

node.js - 启动插件应用程序时出现问题

elasticsearch - 为什么当线程池和队列已满时,elasticsearch 会拒绝几乎所有查询,而不是尽可能多地回答并拒绝剩余的查询?

c# - 查询文档并过滤嵌套字符串列表(即标签)中的特定值

javascript - 恢复 TypeORM 中的特定迁移

c# - 使用C#Nest查询ElasticSearch

c# - 定义应使用多个节点创建哪个节点索引