按查询删除 API 作为 curl 但不在 Node-Red 中工作
Delete By Query API working as curl but not in Node-Red
背景: 我想要实现的是使用单个 API 调用从弹性中删除多个值。我们的应用程序使用 Node-Red 创建后端 API。
我正在使用下面的 curl 命令删除多个文档 ID,它非常有效。它会删除 ID 为 xxxxx
和 yyyyy
.
的文档
POST /tom-access/doc/_delete_by_query
{
"query": {
"terms": {
"_id": [
"xxxxx",
"yyyyy"
]
}
}
}
但是,当我尝试通过 Node-Red(使用 JavaScript 函数)执行相同操作时,出现以下错误。
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation
Failed: 1: query is
missing;"}],"type":"action_request_validation_exception","reason":"Validation
Failed: 1: query is missing;"},"status":400}
这是我在 Node-Red JavaScript 函数中的内容:
if (!msg.headers) msg.headers = {};
msg.req = {
"query": {
"terms": {
"id": [
"xxxxx",
"yyyyy"
]
}
}
};
msg.headers = {
"Content-Type": "application/json",
"Authorization" : "Basic xxxxxxxxxxxxxxxxxxxxx"
};
msg.method = "POST"
// New elastic
msg.url = "http://elastic.test.com/tom-access/doc/_delete_by_query";
return msg;
下一个节点使用上述 msg
对象进行 HTTP CALL,但导致上述错误。我也是 Node-Red、JavaScript 和 Elastic 的新手。嘿嘿!!!
端点可能希望查询位于请求的正文中。
您应该将其设置在 msg.payload
而不是 msg.req
。
背景: 我想要实现的是使用单个 API 调用从弹性中删除多个值。我们的应用程序使用 Node-Red 创建后端 API。
我正在使用下面的 curl 命令删除多个文档 ID,它非常有效。它会删除 ID 为 xxxxx
和 yyyyy
.
POST /tom-access/doc/_delete_by_query
{
"query": {
"terms": {
"_id": [
"xxxxx",
"yyyyy"
]
}
}
}
但是,当我尝试通过 Node-Red(使用 JavaScript 函数)执行相同操作时,出现以下错误。
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: query is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: query is missing;"},"status":400}
这是我在 Node-Red JavaScript 函数中的内容:
if (!msg.headers) msg.headers = {};
msg.req = {
"query": {
"terms": {
"id": [
"xxxxx",
"yyyyy"
]
}
}
};
msg.headers = {
"Content-Type": "application/json",
"Authorization" : "Basic xxxxxxxxxxxxxxxxxxxxx"
};
msg.method = "POST"
// New elastic
msg.url = "http://elastic.test.com/tom-access/doc/_delete_by_query";
return msg;
下一个节点使用上述 msg
对象进行 HTTP CALL,但导致上述错误。我也是 Node-Red、JavaScript 和 Elastic 的新手。嘿嘿!!!
端点可能希望查询位于请求的正文中。
您应该将其设置在 msg.payload
而不是 msg.req
。