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

问题描述 投票:0回答:1

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

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

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

elasticsearch nest
1个回答
1
投票

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

//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

希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.