在ElasticSearch查询中组合must_not [英] Combining must_not in ElasticSearch Query

查看:668
本文介绍了在ElasticSearch查询中组合must_not的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用ElastSearch查询,该查询当前看起来如下:

I'm currently struggling with an ElastSearch query which currently looks the following:

...
"query": {
    "bool": {
        "must_not": [
            {
                "term": {
                    "bool-facet.criteria1": {
                        "value": false
                    }
                }
            },
            {
                "term": {
                    "bool-facet.criteria2": {
                        "value": false
                    }
                }
            }
        ]
    }
}
...

因此,现在当条件1或条件2匹配时,文档将被忽略。查询的外观如何,以便仅忽略符合条件1和条件2的文档?

So now when either criteria1 OR criteria2 matches, the documents are ignored. How must the query look like so that only documents that match criteria1 AND criteria2 are ignored?

推荐答案

因为无法更新elasticsearch版本我不得不找到另一个解决方案。这对我有用:

Since updating elasticsearch version was not possible I had to find another solution. This is what worked for me:

"query": {
    "bool": {
        "must_not" : [
            {
                "query": {
                    "bool": {
                        "must": [
                            {
                               "term": {
                                 "bool-facet.criteria1": false
                               }
                            },
                            {
                               "term": {
                                 "bool-facet.criteria2": false
                               }
                            }
                        ]
                    }
                }
            }
        ]
    }
}

这篇关于在ElasticSearch查询中组合must_not的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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