Elasticseach使用NEST将索引替换为新索引,但别名相同

时间:2020-09-29 05:33:57

标签: elasticsearch nest

谁能告诉我们创建新索引来替换现有索引但具有相同别名的最佳方法是什么。

假设我们有一个名为 properties-2019 的现有索引,别名为 properties

我们想用名为 properties-2020但具有相同别名的新索引来代替它。

我们是否必须:

1-创建新的索引属性-2020

2-删除旧的索引属性-2019

3-然后将别名添加到新创建的索引属性-2020

是否有一种有效的方法来做到这一点。 谢谢

1 个答案:

答案 0 :(得分:0)

基本上是。

首先_reindex数据,然后重命名别名。

重新索引-映射,设置和数据

Reindex Api

POST _reindex?wait_for_completion=false  
{
  "source": {
    "index": "properties-2019"
  },
  "dest": {
    "index": "properties-2020"
  }
}

重命名别名

Update index alias Api

POST /_aliases
{
  "actions" : [
    { "remove" : { "index" : "properties-2019", "alias" : "properties" } },
    { "add" : { "index" : "properties-2020", "alias" : "properties" } }
  ]
}

删除旧索引

DELETE properties-2019

使用NEST -代码未经测试

重新索引

var reindexResponse = client.ReindexOnServer(r => r 
            .Source(s => s.Index("properties-2019"))
            .Destination(d => d.Index("properties-2020"))
            .WaitForCompletion(false)
            );

更新别名

var aliasRes = client.Alias(al => al
    .Add(add => add.Alias("properties").Index("properties-2020"))
    .Remove(remove => remove.Alias("properties").Index("properties-2019"))
);

删除旧索引

client.Indices.Delete("properties-2019");