我试图在将json数据上传到elasticsearch之前创建映射。我不知道如何在sails.js中上传json数据之前实现映射
这是我的bulkupload片段
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"); } });
我想在数据上传之前创建映射。任何人都知道如何在帆中创建映射。
我的Json对象
[ { Name: 'paranthn', Age: '43', Address: 'trichy' }, { Name: 'Arthick', Age: '23', Address: 'trichy' }, { Name: 'vel', Age: '24', Address: 'trichy' } ]
在client.bulk()拨打电话之前,您首先需要client.indices.putMapping()拨打另一个这样的电话,以便为您要通过该bulk电话发送的数据保存正确的映射:
client.bulk()
client.indices.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. });
请记住,所有这些调用是异步的,所以一定要小心,只叫bulk一次,putMapping已成功返回。
putMapping