Elasticsearch:在将json数据上载到Elasticsearch之前,如何创建映射
我试图在将json数据上传到elasticsearch之前创建映射。 在将json数据上传到sails.js之前,我不知道如何实现映射 这是我的上传片段Elasticsearch:在将json数据上载到Elasticsearch之前,如何创建映射,json,node.js,
elasticsearch,sails.js,Json,Node.js,
elasticsearch,Sails.js,我试图在将json数据上传到elasticsearch之前创建映射。 在将json数据上传到sails.js之前,我不知道如何实现映射 这是我的上传片段 var body = []; //row is json data rows.forEach(function(row, id) { body.push({ index: { _index: 'testindex', _type: 'testtype', _id: (id+1)
var body = [];
//row is json data
rows.forEach(function(row, id) {
body.push({ index: { _index: 'testindex', _type: 'testtype', _id: (id+1) } });
body.push(row);
})
client.bulk({
body: body
}, function (err, resp) {
if (err)
{
console.log(err);
return;
}
else
{
console.log("All Is Well");
}
});
我想在上传数据之前创建映射。有人知道如何在sails中创建映射吗
我的Json对象
[ { Name: 'paranthn', Age: '43', Address: 'trichy' },
{ Name: 'Arthick', Age: '23', Address: 'trichy' },
{ Name: 'vel', Age: '24', Address: 'trichy' } ]
听起来您需要。在进行
客户机.bulk()
调用之前,您首先需要进行另一个客户机.index.putMapping()
调用,这样才能保存通过bulk
调用发送的数据的正确映射:
client.indices.putMapping({
"index": "testindex",
"type": "testtype",
"body": {
"testtype": {
"properties": {
"your_int_field": {
"type": "integer"
},
"your_string_field": {
"type": "string"
},
"your_double_field": {
"type": "double"
},
// your other fields
}
}
}
}, function (err, response) {
// from this point on, if you don't get any error, you may call bulk.
});
请记住,所有这些调用都是异步的,因此请注意,只有在
putMapping
成功返回后才调用bulk
。但在批量上载功能之前,我需要在sails.js中进行映射。这可能吗?您好,这对我来说很好。但我json对象将所有东西都返回为字符串,但在我的属性中,我需要将属性设置为整数,我如何才能实现这一点。很高兴它有帮助!我已经更新了答案,添加了一些示例字段,您可以根据自己的喜好进行修改。关于映射的详细信息JSON中的字段数量可能是动态的。那我该怎么做这个映射呢?我已经更新了问题中的json示例数据,请参考。