Elasticsearch NodeJS:如何 return 结果
Elasticsearch NodeJS : How to return result
我正在尝试 return 一个 js 函数调用的值作为
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
var r="";
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well ping');
function getmeresResult(err, result) {
if (err) return err;
console.log("Got res in ping "+result);
return result;
}
r=getmeres(client,getmeresResult);
console.log("inner r is "+r);
return r;
}
});
console.log("outer r is "+r);
这给了我
Got res in ping 12,12,23
inner r is 12,12,23
console.log("outer r is "+r);
根本不会打印出来!这是为什么?我如何获得 client.ping 函数调用的结果 'out'?
我正在尝试 return 一个 js 函数调用的值作为
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
var r="";
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well ping');
function getmeresResult(err, result) {
if (err) return err;
console.log("Got res in ping "+result);
return result;
}
r=getmeres(client,getmeresResult);
console.log("inner r is "+r);
return r;
}
});
console.log("outer r is "+r);
这给了我
Got res in ping 12,12,23
inner r is 12,12,23
console.log("outer r is "+r);
根本不会打印出来!这是为什么?我如何获得 client.ping 函数调用的结果 'out'?