我剛剛進行了彈性搜索,並努力從我的收藏夾中刪除條目。 我需要與此類似 查詢DELETE FROM消息WHERE ID =「1323」」和created_user =‘[email protected]’。彈性搜索刪除操作
以下是我的彈性搜索查詢,當我執行此,它只會刪除特定的id字段,它不採取第二個參數created_user。請幫我解決這個問題。謝謝
var created = "9ed8afe738aa63c28b66994cef1f83c6"
db.delete({
index: 'outboxpro',
type: 'message',
id: req.body.post_id,
created_user: created
}, function (error, resp) {
if (error) {
return next(error);
}
var data = {};
console.log('delete response',resp);
if (resp.hits.successful < 1) {
data = {status: false, message: 'NO POST FOUND TO DELETE', code: 400};
res.send(data);
} else {
return next({status: true, message: 'POST DELETED', data: error, code: 500});
}
});
////編輯 我曾嘗試deleteByQuery,下面是我的代碼
db.deleteByQuery({
index: 'outboxpro',
type: 'message',
body:{
"query": {
"filtered": {
"query": {
"match": {
"_id": {
"query": "Kal4AXi5R9G-IMx4GIKYMw"
}
}
},
"filter": {
"and": [
{
"term": {
"created_user": created
}
}
]
}
}
}
}
}, function (error, resp) {
if (error) {
return next(error);
}
console.log('post deleted');
});
可不可以給你的映射和也你從彈性搜索中得到答案嗎? – 2014-03-12 13:35:41