如何解决在Elasticsearch上按顺序重新索引和删除
我将需要重新索引,删除旧索引并从旧删除的索引中重命名为名称,它将在NodeJS中以随机顺序执行,尝试删除和重命名值不存在。
我确实尝试了没有成功的承诺,并使用.then(function(resp),并且发生了同样的问题。
es.reindex({
refresh: true,body: {
"source": {
"index": current_index
},"dest": {
"index": current_index + ".tmp"
}
}
});
es.indices.delete({
index: current_index,ignore: [404]
},function(err,resp,respcode) {
if (err) {
console.log("Error deleting index " + current_index);
console.log(" Error: " + err);
console.log(" Resp code: " + respcode);
}
});
es.reindex({
refresh: true,body: {
"source": {
"index": current_index + ".tmp"
},"dest": {
"index": current_index
}
}
});
es.indices.delete({
index: current_index + ".tmp",respcode) {
if (err) {
console.log("Error deleting index " + current_index);
console.log(" Error: " + err);
console.log(" Resp code: " + respcode);
}
});
解决方法
这是正确的方法:
const {reindex1Body} = await es.reindex({
refresh: true,body: {
"source": {
"index": current_index
},"dest": {
"index": current_index + ".tmp"
}
}
});
try {
await es.indices.delete({
index: current_index
},{
ignore: [404]
});
} catch (err) {
console.log("Error deleting index " + current_index);
console.log(" Error: " + err);
console.log(" Resp code: " + err.statusCode);
}
const {reindex2Body} = await es.reindex({
refresh: true,body: {
"source": {
"index": current_index + ".tmp"
},"dest": {
"index": current_index
}
}
});
try {
await es.indices.delete({
index: current_index + ".tmp"
},{
ignore: [404]
});
} catch (err) {
console.log("Error deleting index " + current_index);
console.log(" Error: " + err);
console.log(" Resp code: " + err.statusCode);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。