NodeJs and ElasticSearch: Bulk insert error: Failed to derive xcontent

NodeJs and ElasticSearch: Bulk insert error: Failed to derive xcontent

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

提前致谢。

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 }

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

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

此外,您还向 items 推进 element 本身,这是您想要的吗?