在 Nest ElasticSearch 中使用对象初始值设定项语法构建的 Bool 查询中的 MinimumShouldMatch 未附加到 "Should" 子句

MinimumShouldMatch not appending to "Should" clause in a Bool query built using object initializer syntax in Nest ElasticSearch

我正在使用 NEST 对象初始值设定项语法根据用户输入动态构建我的查询。我使用的查询格式是这样的:

"query": {
        "bool": {
            "should": [{
                "range": {
                    "field1": {
                        "lt": x
                    }
                }
            }, {
                "range": {
                    "field2": {
                        "lt": y
                    }
                }
            }],
            "filter": [{
                ...
            }]
        }
    }

上面的查询不起作用,因为 should 被过滤器覆盖,除非 should 子句附加了一个 "minimum_should_match" 字段,如下所示:

"query": {
        "bool": {
            "should": [{
                "range": {
                    "field1": {
                        "lt": x
                    }
                }
            }, {
                "range": {
                    "field2": {
                        "lt": y
                    }
                }
            }],
            "minimum_should_match" = "1",
            "filter": [{
                ...
            }]
        }
    }

但是,我似乎无法找到一种方法来正确定位 minimum_should_match 子句,使其位于 should 和 filter 之间。 BoolQuery 接受一个 "MinimumShouldMatch" 字段,但是它将它附加在过滤器之后而不是应该之前。

有没有办法做到这一点,或者我将不得不使用原始搜索输入?

根据 Russ Cam 的评论,"minimum_should_match" 子句的位置无关紧要。我在测试中犯了一个错误,使我认为过滤器被覆盖了,我错误地认为定位是问题所在。我去重新测试了查询,它工作正常。