Elasticsearch:如何在将json数据上传到Elasticsearch之前创建映射 [英] Elasticsearch: how can i create mapping before upload json data into Elasticsearch

查看:185
本文介绍了Elasticsearch:如何在将json数据上传到Elasticsearch之前创建映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在将json数据上传到弹性搜索之前创建映射。
我不知道如何在sails.js中上传json数据之前实现映射



这是我的批量上传片段

  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
} (err,resp){
if(err)
{
console.log(err);
return;
}
else
{
console.log(All Is Well);
}
});

我想在数据上传之前创建映射。任何人都知道如何在帆中创建映射。 / p>

我的Json对象

  [{Name:'paranthn',Age :'43',地址:'trichy'},
{名称:'Arthick',年龄:'23',地址:'trichy'},
{名称:'vel',年龄: 24',地址:'trichy'}]


解决方案

使您的 client.bulk()调用您首先需要再次创建一个 client.indices.putMapping()为了保存要通过批量调用发送的数据的正确映射:

  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
} ,
//你的其他字段
}
}
}
},function(err,response){
//从这一点开始,if你没有收到任何错误,你可以打电话批量。
});

请记住,所有这些调用都是异步的,所以请小心只调用批量一旦 putMapping 已成功返回。


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' } ]

解决方案

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.

这篇关于Elasticsearch:如何在将json数据上传到Elasticsearch之前创建映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆