我可以使用这个curl命令轻松索引:
curl -XPUT 'http://localhost:9200/prototype_2012.12.27/chow-clfg/Cg-IKkxdTstKAAAAlw-?parent=chow-demo' -d '{
"chow-clfg": {
"@type": "chow-clfg",
"clfg": "Cg6h4VCcMexXAAAAsQc",
"@timestamp": "2012-12-27T08:24:00.000Z",
"count": 1
}
}'
结果:
{
"ok": true,
"_index": "prototype_2012.12.27",
"_type": "chow-clfg",
"_id": "Cg-IKkxdTstKAAAAlw-",
"_version": 1
}
这几乎立即返回结果。
但是,当我使用 Nodejs 的 http.request 方法尝试时:
var http = require('http');
var index = "prototype_2012.12.27";
var server = "chow-clfg";
var options = {
host: 'localhost',
port: '9200',
path: index+'/'+server+'/Cg-IKkxdTstKAAAAlw-?parent=chow-demo',
method: 'PUT'
};
var req = http.request(options, function(res){
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write('{"chow-clfg":{"@type":"chow-clfg","clfg":"Cg6h4VCcMexXAAAAsQc","@timestamp":"2012-12-27T08:24:00.000Z","count":1}}');
req.end;
这只是中途暂停该过程,并且不会向我提供有关其是否成功的反馈。另外,当我在索引中搜索该文档时,我找不到它。
因此,我是否犯了编码错误?或者有什么办法可以解决这个问题吗?
最佳答案
为什么不使用 elasticsearch
模块及其带有 parent
参数的 index
方法?
关于node.js - 如何使用 Nodejs 将父/子文档索引到 Elasticsearch 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051921/