私はノードを使用してREST APIを構築しており、elasticsearchデータベースとの通信を再構築しています。今私はオブジェクトを削除するとき、私はこれをある種の他のオブジェクトへのカスケード削除をしたい。私はこれが本当に弾性検索を使うのではなく、私と一緒に裸であることを知っています。restitutionの複数の機能がelasticsearchクライアントに機能する
は、だからここに私のコードです:だから基本的に私はちょうどホスト名www.test.comを持つすべてのオブジェクトを検索したい
function deleteHostname(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
var endpoints = [];
client.search({
index: 'test',
type: 'something',
body: {
from: 0, size: 100,
query: {
match: {
hostname: 'www.test.com'
}
}
}
}).then(function (error, resp) {
if(error) {
res.send(error);
}
endpoints = resp.hits.hits;
for (index = 0, len = endpoints.length; index < len; ++index) {
client.delete({
index: 'test',
type: 'something',
id: endpoints[index]._id
}, function (error, response) {
if(error) {
res.send(error);
}
});
}
res.send(endpoints);
return next();
});
}
(私はハードそれをテストするために、これをコード化されました)。次に、私が見つけたすべてのオブジェクトを削除したい。それはエラーの経路に従い、私にこれを送ります:
{
"took":1,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":1,
"max_score":2.098612,
"hits":[
{
"_index":"test",
"_type":"something",
"_id":"123456",
"_score":2.098612,
"_source":{
"duration":107182,
"date":"2016-05-04 00:54:43",
"isExceptional":true,
"hostname":"www.test.com",
"eta":613,
"hasWarnings":false,
"grade":"A+",
"ipAddress":"ipip",
"progress":100,
"delegation":2,
"statusMessage":"Ready"
}
}
]
}
}
私の意見では、これはエラーのようですか?だから私はなぜそれをエラーとして戻すのですか?削除した場合:
if(error) {
res.send(error);
}
私のコードから、私は何の応答も得られません。
ご協力いただきありがとうございます。
[OK]をので、私がいましたもう一つの事を変えるために何らかの理由でそれが実際に応答している間にいつも私にエラーを与えていたので、それを変更しました。(function(error、resp){to。(function(resp){ – Matthias
ああ、良い点、私はそれを逃した、コールバックはエラー引数を持っていません。 – Val