node.js - 使用nodejs将索引和字段从couchbase复制到elasticsearch
问题描述
我想使用 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 }
}
我想用上面提到的字段创建索引(因为 couchbase 有这些字段)。
我只能使用以下代码创建索引
const createIndex = async function(indexName){
return await client.indices.create({
index: indexName
});
}
indexes.forEach((item) =>{
console.log('..........item'+item)
client.indices.exists({
index: item.indexName
}, function(err, resp) {
if(err){
console.log(err);
return;
}
if(!resp){
console.log(item.indexName + ' does not exist');
createIndex(item.indexName);
}
else {
console.log(item.indexName + ' already exists');
}
})
})
但我不确定如何创建/添加字段。我尝试添加字段,如下所示
const createIndex = async function(indexName,data){
return await client.indices.create({
index: indexName,
body: data
});
}
indexes.forEach((item) =>{
console.log('..........item'+item)
client.indices.exists({
index: item.indexName
}, function(err, resp) {
if(err){
console.log(err);
return;
}
if(!resp){
console.log(item.indexName + ' does not exist');
createIndex(item.indexName,item.fields);
}
else {
console.log(item.indexName + ' already exists');
}
})
})
它抛出以下错误: StatusCodeError: [not_x_content_exception] 压缩器检测只能在某些 xcontent 字节或压缩的 xcontent 字节上调用
谁能帮我这个?
解决方案
推荐阅读
- bootstrap-4 - Bootstrap 4 - 容器类和圆角?
- wpf - LiveCharts - 填充/描边绑定的 DependencyProperty 不起作用
- swift - 如何识别哪个单元格被点击了一次,哪个单元格被点击了两次
- ms-access - 在 Print Preview Access 2013 中打开报告
- java - for循环中的并发方法执行
- c# - Binding model with multiple properties in UserControl using one DependencyProperty
- apache-flink - Order of events with chained keyBy calls on same key
- javascript - “Access-Control-Allow-Origin”标头错误。响应具有 HTTP 状态代码 503
- amazon-web-services - 列出超过 x 天/月的 ami
- html - Flexbox - same height on all cards