简体   繁体   English

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

[英]Recreate ElasticSearch Index with Nest 7.x

I would like to be able to recreate an ElasticSearch index, in production, without any downtime.我希望能够在生产中重新创建 ElasticSearch 索引,而无需停机。

With previous versions of Nest (5 and earlier) it was possible to do that by having an alias that points at your original index, creating a new index, updating the alias to point to the new index, and then dropping the original index.对于以前版本的 Nest(5 及更早版本),可以通过使用指向原始索引的别名、创建新索引、更新别名以指向新索引,然后删除原始索引来实现这一点。

Is it possible to achieve something similar, without downtime, with Nest 7.x?是否可以使用 Nest 7.x 实现类似的功能,而无需停机? If so, how.如果是,如何。 If you can provide an example with Object Initializer Syntax, that would be most helpful.如果您可以提供一个带有对象初始化程序语法的示例,那将是最有帮助的。

Please find an example with comments below请在下面找到带有评论的示例

//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);
}

Output:输出:

Indices pointing to alias:
index2

Hope that helps.希望有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM