如何删除包括多个条件的索引?

时间:2019-01-03 21:17:17

标签: regex elasticsearch elastic-stack elasticsearch-5

我尝试删除符合所选条件的指定索引。

此刻,我使用如下所示的一种条件删除它们

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,

            }
        }
    }
}

您有任何想法该怎么做吗?

1 个答案:

答案 0 :(得分:2)

我想使用布尔查询将是正确的方向,类似这样的方法应该起作用:

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
                    }               
                }
            ]
        }
    }
}