gpt4 book ai didi

elasticsearch - Elasticsearch使用NEST将索引替换为新索引但别名相同

转载 作者:行者123 更新时间:2023-12-03 02:13:28 24 4
gpt4 key购买 nike

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

最佳答案

基本上是。
首先用_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");

关于elasticsearch - Elasticsearch使用NEST将索引替换为新索引但别名相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64113478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com