背景:我想要实现的是使用单个 API 调用从弹性中删除多个值。我们的应用程序使用 Node-Red 创建后端 API。
我正在使用下面的 curl 命令来删除多个文档 ID,它的工作原理就像一个魅力。它会删除使用 idxxxxx和找到的文档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":"验证失败:1:查询丢失;"}],"type":"action_request_validation_exception","reason": “验证失败:1:查询丢失;”},“状态”: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;
下一个节点使用上述对象进行 HTTP CALL,msg但导致上述错误。我也是 Node-Red、JavaScript 和 Elastic 的新手。嘻嘻!!!