I'm new to elasticsearch and also for couchbase and I want to replicate documents from couchbase to elasticsearch using nodejs.
Below are the indexes we have in 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 }
}
I tried to create a similar index in elasticsearch with below code
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))
})
I'm able to create index,but if I rerun the code, it shows error: [resource_already_exists_exception] index [idx_dest/0iR-fZLdSty0oLVaQhNTXA] already exists, with { index_uuid="0iR-fZLdSty0oLVaQhNTXA" & index="idx_dest" }
I want it to ignore the existing index and add a new index if any.
Can anyone help me with it?