Recreate ElasticSearch Index with Nest 7.x

扶醉桌前 提交于 2020-12-13 12:09:24

问题


I would like to be able to recreate an ElasticSearch index, in production, without any downtime.

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.

Is it possible to achieve something similar, without downtime, with Nest 7.x? If so, how. If you can provide an example with Object Initializer Syntax, that would be most helpful.


回答1:


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.



来源:https://stackoverflow.com/questions/59929255/recreate-elasticsearch-index-with-nest-7-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!