背景:我想要实现的是使用单个API调用从弹性中删除多个值。我们的应用程序使用Node-Red来创建后端API。
我使用下面的curl命令来删除多个doc 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”:“验证失败:1:查询丢失;”}],“类型”:“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;
下一个节点使用上面的msg
对象进行HTTP CALL,但会导致上述错误。我也是Node-Red,JavaScript和Elastic的新手。 HEEELP!
端点可能期望查询位于请求的主体中。
你应该在msg.payload
而不是msg.req
下设置它。