【发布时间】:2021-11-30 06:45:45
【问题描述】:
我是 elasticsearch 和 couchbase 的新手,我想使用 nodejs 将文档从 couchbase 复制到 elasticsearch。
以下是我们在 couchbase 中的索引:
const destinationIndexes = {
indexName: 'idx_dest'
fields: ["id", "name"]
options: { ignoreIfExists: true }
}
const testIndexes = {
indexName: 'idx_test',
fields: ["testName", "test", "testId"]
options: { ignoreIfExists: true }
}
const statusIndexes = {
indexName: 'idx_status',
fields: ["statusSchema"]
options: { ignoreIfExists: true }
}
我尝试使用以下代码在 elasticsearch 中创建类似的索引
const createIndex = async function(indexName){
return await client.indices.create({
index: indexName
});
}
indexes.forEach((item) =>{
console.log('..........item'+item)
const resp = createIndex(item.indexName);
console.log('...........resp..............'+JSON.stringify(resp))
})
我可以创建索引,但是如果我重新运行代码,它会显示错误: [resource_already_exists_exception] 索引 [idx_dest/0iR-fZLdSty0oLVaQhNTXA] 已经存在,{ index_uuid="0iR-fZLdSty0oLVaQhNTXA" & index="idx_dest" }
我希望它忽略现有索引并添加新索引(如果有)。
谁能帮帮我?
【问题讨论】:
标签: node.js elasticsearch