elasticseach使用nest将索引替换为新索引,但别名相同

p8ekf7hl  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(330)

有谁能告诉我们,创建一个新索引来替换一个别名相同的现有索引的最佳方法是什么。
假设我们有一个名为properties-2019的索引,其中包含别名属性。
我们想用一个名为properties-2020但别名相同的新索引来替换它。
我们必须:
1-创建新索引properties-2020
2-删除旧索引属性-2019
3-然后将别名添加到新创建的索引properties-2020中
有没有一个有效的方法来做到这一点。谢谢

7fhtutme

7fhtutme1#

基本上是的。
第一 _reindex 删除数据,然后重命名别名。
重新索引-Map、设置和数据
重新索引api

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

重命名别名
更新索引别名api

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

删除旧索引

DELETE properties-2019

使用嵌套代码还没有经过测试
重新索引

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");

相关问题