我可以使用这个 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;
这只是中途暂停该过程,并且不会给我关于它是否成功的反馈。另外,当我在索引中搜索文档时,我找不到它。
因此,我犯了编码错误吗?或者有什么办法可以解决这个问题?