【发布时间】:2018-07-27 01:42:50
【问题描述】:
背景
在我的节点应用程序中,我试图从 SQL 表中索引返回的值。我一直在阅读文档,我认为我应该使用批量功能来做到这一点。我正在尝试使用嵌套数据类型,但我发现文档有点不清楚。
这里有三个功能。
- 索引
- 放置映射
- 散装
当我尝试添加一个索引时,它工作正常。但是当我尝试添加批量索引时,它说索引不存在。这让我假设我需要创建索引,然后使用putMapping 添加嵌套映射。无论哪种方式,我尝试都会出错。最近我收到错误,
"请求正文是必需的"},"status":400}',
问题
当我尝试创建在没有正文键的情况下尝试创建的索引时出现此错误。我在想我需要先用映射创建索引,这样我才能输入批量数据。我认为我的问题是我没有使用正确的功能。
示例
索引
exports.createIndex = () => {
esClient.index({
index: "products",
type: "product",
refresh: "true"
}, (error, response) => {
if(error) {
console.log('Put Index Error ', error);
} else {
this.createMapping();
console.log('Put Index Response ', response);
}
});
};
putMapping
exports.createMapping = () => {
esClient.indices.putMapping({
index: "products",
type: "product",
body: {
mappings: {
product: {
properties: {
variantId: { type: "text" },
productId: { type: "text" },
keyStrengths: { type: "text" },
something: {
type: "nested",
properties: {
type: { type: "text" },
label: { type: "text" },
items: {
type: "nested",
properties: {
value: {
type: "text"
},
characteristic: {
type: "text"
}
}
}
}
}
}
}
}
}
}, (error, response) => {
if(error) {
console.log('Put Index Error ', error);
} else {
console.log('Put Index Response ', response);
}
});
};
散装
esClient.bulk({})
问题
请告诉我创建新索引的正确方法,然后批量插入从数据库返回的数据。我不清楚我是否需要使用所有这三个功能,或者我在哪里出错了。
我的目标是批量插入具有数组的对象数组 里面的对象。
【问题讨论】:
标签: node.js elasticsearch