post_filter产生的结果与普通过滤器不同

时间:2018-01-29 21:00:26

标签: elasticsearch

我调整了一个查询,我必须在聚合后应用过滤器,但现在我在结果集中看到了不同的项目。这几乎就像现在正在完全忽略带有[“filters”] [“bool”] [“should”]的项目。

这很正常:

"query": {
    "bool": {
        "must": {
          ...
        },
        "filter": {
            "bool": {
                "should": [{
                    "term": {
                        "any_pickup_options": true
                    }
                }, {
                    "term": {
                        "local_delivery": true
                    }
                }],
                "must": [{
                    "term": {
                        "active": true
                    }
                }]
            }
        }
    }
}

这就是失败的原因:

"query": {
    "bool": {
        "must": {
          ...
        }
    }
},
"post_filter": {
    "bool": {
        "should": [{
            "term": {
                "any_pickup_options": true
            }
        }, {
            "term": {
                "local_delivery": true
            }
        }],
        "must": [{
            "term": {
                "active": true
            }
        }]
    }
}

考虑[“post_filters”] [“bool”] [“must”]约束。但结果集不包含any_pickup_optionslocal_delivery设置为true的任何项目。

1 个答案:

答案 0 :(得分:0)

知道了。您必须在过滤器上下文中指定minimum_should_match。

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html