弹性搜索删除操作 [英] Elastic search delete operation

查看:206
本文介绍了弹性搜索删除操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的弹性搜索和努力从我的收藏中删除一个条目。
我需要一个类似于这个的查询
DELETE FROM message WHERE id ='1323'和created_user =user@gmail.com。



以下是我的弹性搜索查询,当我执行这个,它只删除特定的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:'消息',
body:{
query:{
filtered:{
query:{
match:{
_id:{
query:Kal4AXi5R9G-IMx4GIKYMw
}
}
},
filter:{
and :[
{
term:{
created_user:created
}
}
]
}
}
}
}
},function(error,resp){
if(error){
return next(err或);
}
console.log('post deleted');
});


解决方案

删除API将完全符合您的要求,



首先要做的是搜索要删除的文档,从而构建一个查找所有文档的搜索查询ID为'1323',一个created_user为'user@gmail.com'。从返回的文档中,您可以检索您需要传递到删除API的文档ID。



http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs- delete.html


Am new to elastic search and struggling to delete an entry from my collection. I need a query similar to this one DELETE FROM message WHERE id='1323'" and created_user = "user@gmail.com".

Following are my elastic search query, when i execute this, its only deleting the particular id field, its not taking the second argument created_user. Please help me to solve this issue. Thanks

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});
            }
});

//// EDIT I have tried deleteByQuery, following are my code

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');
});

解决方案

The delete API will do exactly what you want, just in a slightly round-about way.

What you'll have to do first is search for the documents you want to delete, so construct a search query that find all documents with the id of '1323' and a created_user of 'user@gmail.com'. From the returned documents you'll be able to retreive the document ID which you then need to pass through to the delete API.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html

这篇关于弹性搜索删除操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆