【问题标题】:Recreate ElasticSearch Index with Nest 7.x使用 Nest 7.x 重新创建 ElasticSearch 索引
【发布时间】:2020-01-27 10:28:01
【问题描述】:

我希望能够在生产中重新创建 ElasticSearch 索引,而无需任何停机时间。

使用旧版本的 Nest(5 和更早版本),可以通过使用指向原始索引的别名、创建新索引、更新别名以指向新索引,然后删除原始索引来做到这一点索引。

Nest 7.x 是否可以在不停机的情况下实现类似的功能?如果是这样,如何。如果你能提供一个对象初始化器语法的例子,那将是最有帮助的。

【问题讨论】:

标签: elasticsearch nest


【解决方案1】:

请在下面找到一个带有 cmets 的示例

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

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2017-04-04
    • 2021-05-02
    • 2017-12-29
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多