【发布时间】:2019-09-06 02:58:37
【问题描述】:
我正在邮递员中创建映射索引,但出现以下错误。 我正在尝试创建一个索引,该索引将使用我创建的 index.js 函数与我的弹性搜索 firebase 服务器进行通信。可能是什么问题?
这是我的代码
"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"
}
}
}
}
这里是 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 => {
console.log("ElasticSearch response", response);
return 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, -LcajBAxUn3jrq0EHzYa]"}],
这是我在 firebase 中的数据库示例
-LcajBAxUn3jrq0EHzYa
city:
contact_email:
country:
description:
image:
post_id:
price:
state_province:
title:
请帮助我确定我的错误可能在哪里。
【问题讨论】:
-
你能在这里提供更多细节吗?这是否是请求正文的一部分?服务器代码是什么?你到底想达到什么目的?请提供更多背景信息,以便其他人能够理解您的问题并为您提供帮助。
-
你找到解决办法了吗?
标签: node.js firebase elasticsearch postman