Elasticsearch:如何在将Json数据上传到Elasticsearch之前创build映射
我试图在将json数据上传到elasticsearch之前创build映射。 我不知道如何在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"); } });
我想在数据上传之前创build映射。任何人都知道如何在sails中创build映射。
我的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.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. });
请记住,所有这些调用都是asynchronous的,所以一旦putMapping
成功返回,只需调用bulk
。
听起来像你需要PutMapping 。