[英]Why can't Elasticsearch bulk API parse my JSON?
我有我此类JSON数据PUT
经由HTTP请求到Elasticsearch API / _bulk端点荷兰国际集团:
{"update":{"_id":1,"_type":"myType","_index":"myIndex"}}
{"doc":{"id":1,"name":"Foo"},"doc_as_upsert":true}
{"update":{"_id":2,"_type":"myType","_index":"myIndex"}}
{"doc":{"id":2,"name":"Bar"},"doc_as_upsert":true}
当我PUT
通过邮差(谷歌的Chrome浏览器应用程序)的数据它成功地工作。
当我PUT
通过我的Node.js脚本(一个数据request()
调用),我得到这个错误:
{
"error" : {
"root_cause" : [ {
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
} ],
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
},
"status" : 400
}
我正在双向发送(假设是)完全相同的数据,但只有Postman在工作。 我以\\ n字符(包括最后一个)结束每一行,并且我相信自己的格式是正确的。
我做错什么了吗?
编辑:节点代码(简体):
var sourceData = JSON.parse(fs.readFileSync('test-data.json', 'utf8')),
sourceData.forEach(function(data) {
var docid = data.id;
updates.push(JSON.stringify({
update: {
_id: docid,
_type: config.elasticsearch.type,
_index: config.elasticsearch.index
}
}));
updates.push(JSON.stringify({
doc: data,
doc_as_upsert: true
}));
});
updates = updates.join("\n") + "\n";
request({
uri: 'http://my-endpoint/_bulk',
method: 'POST',
data: updates,
proxy: 'http://' + config.proxy.host + ':' + config.proxy.port
}, function() { ... });
您需要使用body
参数发送更新,而不是data
(适用于多部分请求)
request({
uri: 'http://my-endpoint/_bulk',
method: 'POST',
body: updates, // <---- change this
proxy: 'http://' + config.proxy.host + ':' + config.proxy.port
}, function() { ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.