我正在尝试使用Firebase云功能将数据推送到我的ElasticSearch索引,并且在Firebase中遇到一些错误。问题可能在哪里?
这是我的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_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 => {
return console.log("ElasticSearch response", response);
})
});
以下是Firebase中收到的错误
StatusCodeError: 400 - {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [posts] as the final mapping would have more than 1 type: [_doc, -LcVpBay0SLV3c6fnpgt]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [posts] as the final mapping would have more than 1 type: [_doc, -LcVpBay0SLV3c6fnpgt]"},"status":400}
at new StatusCodeError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:32:15)
这是我在邮递员中的索引代码
{
"mappings":{
"properties":{
"city":{
"type": "text"
},
"contact_email":{
"type": "text"
},
"country":{
"type": "text"
},
"description":{
"type": "text"
},
"image":{
"type": "text"
},
"post_id":{
"type": "text"
},
"state_province":{
"type": "text"
},
"title":{
"type": "text"
}
}
}
}
答案 0 :(得分:1)