首页 > 解决方案 > 如何删除包含多个条件的索引?

问题描述

我尝试删除满足所选条件的指定索引。

目前我使用如下所示的一种条件删除它们

localhost:9200/pictures/picture/_delete_by_query?pretty
{
    "query": {
        "regexp":{
                "tag": ".*something.*"
            }
        }
    }
}

我想以这种方式删除它们

localhost:9200/pictures/picture/_delete_by_query?pretty
{
    "query": {
        "regexp":{
                "tag": ".*something.*",
                "path": "this/is/my/path",
                "user_id": 2,

            }
        }
    }
}

你有什么想法我该怎么做?

标签: regexelasticsearchelastic-stackelasticsearch-5

解决方案


我想使用 bool 查询将是正确的方向,这样的事情应该可以工作:

localhost:9200/pictures/picture/_delete_by_query?pretty
{
    "query": {
        "bool": {
            "must": [
                {
                    "regexp":{
                            "tag": ".*something.*",
                            "path": "this/is/my/path",
                            "user_id": 2,

                        }
                    }               
                },
                {
                    "term": {
                        "path.keyword": "this/is/my/path"
                    }
                },
                {
                    "term": {
                        "user_id.keyword": 2
                    }               
                }
            ]
        }
    }
}

推荐阅读