背景
在我的节点应用程序中,我正试图索引来自SQL表的返回值。我一直在阅读文档,我想我应该使用bulk函数来完成这项工作。我试图使用嵌套数据类型,但发现文档有点不清楚。
这里有三个功能在起作用。
-
指数
-
电脑绘图
-
大量的
当我尝试添加一个索引时,它工作得很好。但是,当我尝试添加散列索引时,它表示索引不存在。这使我假设我需要创建索引,然后使用
putMapping
. 不管怎样,我都会出错。最近我发现了一个错误,
“请求正文是必需的”},“状态”:400}',
问题
我在尝试创建索引时遇到此错误,我正尝试在没有body键的情况下创建索引。我想我需要先用映射创建索引,这样我就可以输入大量数据了。我想我的问题是我没有使用正确的函数。
例子
指数
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);
}
});
};
电脑绘图
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({})
问题
请告诉我创建新索引的正确方法,然后批量插入从数据库返回的数据。我不清楚我是否需要使用这三种功能,或者我在哪里出了问题。
我的目标是大容量插入具有
里面的东西。