无法使用nodejs的Axios将数据添加到弹性中
我正在尝试使用Axios和nodejs将数据导入弹性搜索中,但是我遇到了400个不良请求错误,我已经在弹性中创建了索引,这是sales-enable-data索引,我正在尝试使用该索引添加数据,但是我变得越来越糟请求错误
代码
app.get("/import/data", async (req, res) => {
const current = {
project_name: "java",
delivery_manager: "Yawhe",
project_manager: "Ruth",
};
const data = JSON.stringify(current);
await axios({
url: "http://localhost:9200/sales-enable-data-index/_doc",
method: "POST",
headers: {
"Content-Type": "application/json",
},
auth: {
username: "username",
password: "password",
},
body: data,
})
.then((response) => {
return res.status(200).send(response);
})
.catch((err) => {
return res.status(500).send(err);
});
});
错误
"code": "ERR_BAD_REQUEST",
"status": 400
I am trying to import data into elastic search using axios and nodejs but I am getting 400 bad request error, I have created index in elastic which is sales-enable-data index I am trying to add data using that index but I am getting bad request error
Code
app.get("/import/data", async (req, res) => {
const current = {
project_name: "java",
delivery_manager: "Yawhe",
project_manager: "Ruth",
};
const data = JSON.stringify(current);
await axios({
url: "http://localhost:9200/sales-enable-data-index/_doc",
method: "POST",
headers: {
"Content-Type": "application/json",
},
auth: {
username: "username",
password: "password",
},
body: data,
})
.then((response) => {
return res.status(200).send(response);
})
.catch((err) => {
return res.status(500).send(err);
});
});
Error
"code": "ERR_BAD_REQUEST",
"status": 400
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查Axios请求。请求无法找到端点
Check the Axios request. Request unable to find the endpoint
您是发送字符串而不是JSON,这就是为什么Elasticsearch表示它不喜欢收到的数据的原因。
尝试在没有
json.stringify
的情况下执行请求:You're sending String instead of JSON, this is why ElasticSearch says it does not like the data it's receiving.
Try doing the request without the
JSON.stringify
like this: