繁体   English   中英

如何批量发送请求? Elasticsearch

[英]How to send request with bulk? Elasticsearch

我有一个带有数据的对象,我想将此数据发送到elasticsearch容器

      for(let key in params)
               {
                  bulk.push(JSON.stringify({
                index: {
                    _id: params[ key ][ 'id' ],
                    _type: 'id',
                    _index: 'geo'
                }
            }));
            bulk.push(JSON.stringify(params[key]));
        }
        let bulks = bulk.join("\n") + "\n";

我提出要求

let cat =  request(
    {
        'method' : 'PUT',
        'uri'    : 'http://dev4.int10h.net:40024/_bulk',
        'body'   : bulks ,
        'json'   : true,
        'headers':
            [
                'Content-Type: application/x-ndjson'
            ],
        'agent'  : false
    }
);

但是有错误

未处理的拒绝StatusCodeError:400-{“错误”:{“ root_cause”:[{“类型”:“ illegal_argument_exception”,“原因”:“批量请求必须由换行符[\\ n]”}],“ type终止“:” illegal_argument_exception“, ”原因“:”批量请求必须由换行[\\ n]“},”状态“:400 }在新的StatusCodeError(/ usr / lib / node_modules / request-promise / node_modules / Request.plumbing.callback(/usr/lib/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:104上的request-promise-core / lib / errors.js:32:15): 33)在Request.self.callback(//在[Request.RP $ callback [作为_callback](/usr/lib/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:46:31)要求时位于Request.emit(events.js:182:13)上的usr / lib / node_modules / request / request.js:185:22)。 (/usr/lib/node_modules/request/request.js:1161:10)位于IncomingMessage的Request.emit(events.js:182:13)。 (/usr/lib/node_modules/request/request.js:1083:12)位于EndReadableNT(_stream_visible.js)的IncomingMessage.emit(events.js:187:15)的Object.onceWrapper(events.js:273:13) :1098:12)在process.internalTickCallback(internal / process / next_tick.js:72:19)

如何正确发送批量?

批量类型string 在此处输入图片说明

不确定是否对您有帮助,但是在这里我发现了_bulkJSON.stringify类似问题。

答案是:

看起来您的有效负载中的元字符未转换为换行符。 如果您改为使用elasticsearch.js客户端,它将为您处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM