很抱歉再次提出这个问题,但我尝试了所有解决方案,但仍然遇到此错误。我正在将elastic search
连接到我的Android项目。我被困在这里,我已经尝试了一切。
错误快照:
这是我的index.js
文件,我进行了所有更改,但仍然收到错误。
const functions = require('firebase-functions');
const request = require('request-promise')
exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')
.onWrite(( change,context) => {
let postData = change.after.val();
let post_id = context.params.post_id;
console.log('Indexing post:', postData);
let elasticSearchConfig = functions.config().elasticsearch;
let elasticSearchUrl = elasticSearchConfig.url + 'posts/post/' + post_id;
let elasticSearchMethod = postData ? 'POST' : 'DELETE';
let elasticSearchRequest = {
method: elasticSearchMethod,
url: elasticSearchUrl,
auth:{
username: elasticSearchConfig.username,
password: elasticSearchConfig.password,
},
body: postData,
json: true
};
return request(elasticSearchRequest).then(response => {
console.log("ElasticSearch response", response);
});
});
这是我的package.json文件的代码
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"request": "^2.88.0",
"request-promise": "^4.2.4"
},
"private": true
}
这是我的数据库的快照