【问题标题】:Elastic Search bulk operation弹性搜索批量操作
【发布时间】:2019-06-03 06:33:34
【问题描述】:

我真的不明白为什么当我运行批量插入时,我在没有执行任何删除操作的情况下丢失了同一个集合中的先前数据? 这很奇怪。

有什么想法吗?

var client = new elasticsearch.Client( {  
  hosts: [
    'http://localhost:9200/'    
  ]
})

。 . .

InserTweets: function (arrayobj, callback) {
        var items=[];

        var count=1;
        arrayobj.forEach(element => {
            items.push({ index:  { _index: 'twitter', _type: 'tweet', _id: count }},element);
            count++;
        });


         client.bulk({body:items}, function (err, resp, status) {
            callback(err, resp, status);
        }, function (err, resp, status) {
           console.log(err);
        }); 
    }

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您正在将_id 设置为count,因此在第二个操作中将现有记录覆盖/更新为新记录。

    _id 对于每条记录都必须是唯一的。

    element 有什么独特的东西,比如你可以使用的 id

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-09
      • 2022-06-16
      • 2018-11-28
      • 2014-04-16
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      相关资源
      最近更新 更多