Elasticsearch: how can i create mapping before upload json data into Elasticsearch

混江龙づ霸主 提交于 2019-12-14 02:32:26

问题


I'm trying to create mapping before uploading json data into elasticsearch. I don't know how to implement mapping before uploading json data in sails.js

This is my bulkupload snippet

     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");
                      }
      });

I want to create mapping before data upload.can any one know how to create mapping in sails.

my Json object

 [ { Name: 'paranthn', Age: '43', Address: 'trichy' },
      { Name: 'Arthick', Age: '23', Address: 'trichy' },
      { Name: 'vel', Age: '24', Address: 'trichy' } ]

回答1:


Before making your client.bulk() call you first need to make another client.indices.putMapping() call like this in order to save the correct mapping for the data you're about to send via the bulk call:

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.
});

Remember that all these calls are asynchronous, so be careful to only call bulk once putMapping has returned successfully.




回答2:


Sounds like you need PutMapping.



来源:https://stackoverflow.com/questions/32451702/elasticsearch-how-can-i-create-mapping-before-upload-json-data-into-elasticsear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!