【问题标题】:NodeJs and ElasticSearch: Bulk insert error: Failed to derive xcontentNodeJs 和 ElasticSearch:批量插入错误:无法派生 xcontent
【发布时间】:2018-11-17 22:36:19
【问题描述】:

我找不到我的错误,我正在尝试使用带有弹性搜索库的批量方法将元素数组插入到弹性搜索中。

提前致谢。

InserTweets: function (arrayobj, callback) {

        var items=[];

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

        console.log(items);

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

错误:

{ error:
   { root_cause: [ [Object] ],
     type: 'parse_exception',
     reason: 'Failed to derive xcontent' },
  status: 400 }

【问题讨论】:

    标签: node.js elasticsearch bulkinsert


    【解决方案1】:

    属性body 的值必须是对象数组,而不是对象数组。

    这个client.bulk({body: [items]}...应该是client.bulk({body: items}...

    此外,你还推入items element 本身,这是你想要的吗?

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 2021-05-12
      • 2016-08-11
      相关资源
      最近更新 更多