我正在将弹性搜索连接到我的Android项目,但我正在这一步,但每次我在我的应用程序中执行操作时都会收到错误:TypeError:无法读取属性' val'未定义的
以下是NotePad中的代码
const functions = require('firebase-functions');
const request = require('request-promise')
exports.indexPostsToElastic = functions.database.ref('/post/{post_id}')
.onWrite(event => {
let postData = event.data.val();
let post_id = event.params.post_id;
console.log('Indexing post:', postData);
let elasticSearchConfig = functions.config().elasticsearch;
let elasticSearchUrl = elasticSearchConfig.url + 'post/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);
return null;
});
});