我正在一个项目中使用弹性搜索从firebase数据进行搜索,并尝试使用angularjs将数据添加到弹性,但错误如下:
{"data":"","status":0,"config":{"method":"PUT","transformRequest":[null],"transformResponse":[null],
我的代码是:
var inputJson =
{
"mappings": {
"carprev": {
"properties": {
"agepolicy33": {
"type": "text"
},
"aircondition33": {
"type": "text"
},
"year33": {
"type": "integer"
}
}
}
}
}
var corsHeaders = {
origin: ["*"],
headers: ['Origin', 'X-Requested-With', { 'Content-Type':
'application/x-www-form-urlencoded' }],
credentials: true,
additionalHeaders: ['access-control-allow-headers', 'Access-Control-
Allow-Origin, Access-Control-Allow-Headers, Origin, X-Requested-With,
Content-Type, CORRELATION_ID'],
additionalExposedHeaders: ['access-control-allow-headers', 'Access-
Control-Allow-Origin, Access-Control-Allow-Headers, Origin, X-
Requested-With, Content-Type, CORRELATION_ID']
};
$http({
method: "PUT",
// headers: ['Origin', 'X-Requested-With', 'Content-Type'],
url: "http://xx.xxx.xxx.xxx/elasticsearch/test/5",
data: inputJson
}).then(function mySuccess(response) {
console.log(response);
}, function myError(err) {
var cjson = JSON.stringify(err);
console.log(err);
});
但使用postman和查询数据从弹性
中插入弹性搜索中的相同json如果有人可以解决,赞赏
答案 0 :(得分:0)
您可以尝试将内容类型更改为json。
$http({
method: "PUT",
headers: {'Content-Type': 'application/json'},
url: "http://xx.xxx.xxx.xxx/elasticsearch/test/5",
data: inputJson
}).then(function mySuccess(response) {
console.log(response);
}, function myError(err) {
var cjson = JSON.stringify(err);
console.log(err);
});