我希望能够在生产中重新创建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/