Воссоздайте индекс ElasticSearch с помощью Nest 7.x - PullRequest
0 голосов
/ 27 января 2020

Я хотел бы иметь возможность воссоздать индекс ElasticSearch в рабочем состоянии без простоев.

В предыдущих версиях Nest (5 и более ранних) это можно было сделать, имея псевдоним, указывающий в исходном индексе создайте новый индекс, обновите псевдоним, чтобы он указывал на новый индекс, а затем отбросьте исходный индекс.

Можно ли добиться чего-то подобного без простоя с помощью Nest 7.x? Если так, то как. Если вы можете предоставить пример с синтаксисом инициализатора объекта, это будет очень полезно.

1 Ответ

1 голос
/ 27 января 2020

Ниже приведен пример с комментариями

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

Надеюсь, это поможет.

...