【发布时间】:2018-07-01 17:14:41
【问题描述】:
我知道这个问题已经被问过好几次了,但解决方案并不适用于我的情况。我已经使用这两个命令启动了ElasticSearch、Kibana:
bin/elasticsearch
bin/kibana
并且服务器运行良好,当使用浏览器访问http://localhost:9200时,我得到以下结果:
{
"name" : "vg7RnLh",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "gqDf0H67TxGZGYigAlu2mQ",
"version" : {
"number" : "6.1.2",
"build_hash" : "5b1fea5",
"build_date" : "2018-01-10T02:35:59.208Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
当使用kibana 时,一切正常。这里是我写的firebase云函数,如果有什么不对的地方,我想就在这里:
exports.downloadUserInfo = functions.https.onRequest((req, res) => {
const { uid } = req.query;
const searchConfig = {
uri: 'http://localhost:9200/users/user/' + uid,
method: 'GET'
};
request(searchConfig)
.then((result) => {
console.log(result);
return res.status(200).send(result);
})
.catch((error) => {
console.log(error);
return res.status(400).send(error);
});
});
其中request 是yarn add request request-promise 安装的模块。然后,当使用Postman 测试我的 API 时,我得到了这个错误:
我该如何解决这个问题?
更新
我也在使用命令node app.js 运行flashlight。将新用户插入数据库时,新用户也会自动插入到 ElasticSearch 服务器(localhost),但是,当我尝试读取时,它会抛出请求错误
第二次更新
这是创建用户的 API:
exports.register = functions.https.onRequest((req, res) => {
const { firstName, lastName } = req.body;
admin.database().ref('users').push({ firstName, lastName })
.then(() => res.status(201).send())
.catch(() => res.status(400).send());
});
当这个 API 创建一个新用户时,这个用户会自动插入到我的本地 ElasticSearch 服务器,因为我正在使用flashlight 插件。我不明白为什么当我尝试从同一台服务器读取时,会出现请求错误。
【问题讨论】:
-
您是否使用
firebase deploy运行完全部署到 Cloud Functions 的代码? -
@DougStevenson 是的,部署成功
标签: javascript firebase elasticsearch google-cloud-functions