小编Tec*_*arn的帖子

忽略索引(如果已经存在)并使用nodejs在elasticsearch中创建/添加新索引

我是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 }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用下面的代码在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))
})
Run Code Online (Sandbox Code Playgroud)

我可以创建索引,但如果重新运行代码,它会显示错误: [resource_already_exists_exception] 索引 [idx_dest/0iR-fZLdSty0oLVaQhNTXA] 已存在,其中 …

node.js elasticsearch

2
推荐指数
1
解决办法
2156
查看次数

标签 统计

elasticsearch ×1

node.js ×1