简体   繁体   English

最小数量应匹配,应与POST匹配

[英]Minimum Number Should Match, Should match with POST

I'm trying to query an elasticsearch 5.2 rest endpoint: 我正在尝试查询elasticsearch 5.2 rest终结点:

{
    "query": {
        "bool": {
            "should": [
                {"match": { "file-source": "css" }},
                {"match": { "file-source": "js" }}
            ],
            "minimum_number_should_match": 2
        }
    }
}

However, this returns NO HITS in ElasticSearch, I don't understand why this doesn't work and the ElasticSearch documentation has very few examples. 但是,这在ElasticSearch中没有返回任何结果,我不明白为什么这不起作用,并且ElasticSearch文档中只有很少的示例。

I'm trying to match both. 我正在尝试两者都匹配。 But it could be either OR. 但这可能是OR。

There is file-source: "css", file-source: "js", file-source: "json" 有文件源:“ css”,文件源:“ js”,文件源:“ json”

But I want an option of BOTH CSS AND JS... 但是我想同时选择CSS和JS ...

Here's some example Java code when testing the same with Java API: 这是使用Java API测试相同代码时的一些示例Java代码:

// conditions met from the form
query.should(QueryBuilders.matchQuery("file-source", "css"));
query.should(QueryBuilders.matchQuery("file-source", "js"));
query.minimumNumberShouldMatch(2);

Lets explain the given query. 让我们解释给定的查询。

"should": [
            {"match": { "file-source": "css" }},
            {"match": { "file-source": "js" }}
        ]

This will return all the documents that have file-source as css or js. 这将返回所有文件源为css或js的文档。

      A = <documents with file-source = css or jss>

     "minimum_number_should_match": 2
      B = A <documents with file-source at least 2 of css, jss>

This will narrow the results and will restrict A to the documents that has both css and js. 这将缩小结果范围,并将A限制为同时具有css和js的文档。 Remember "css OR js" contains "css and js" as well. 请记住,“ css OR js”也包含“ css和js”。 But here in your case it seems like each doc has unique file source so A will become an empty set as there is no "css and js". 但是在您的情况下,似乎每个文档都具有唯一的文件源,因此A将成为空集,因为没有“ css和js”。

In this case B becomes empty as there is no document that have file-source = css and jss 在这种情况下,由于没有文档具有file-source = css和jss,因此B变为空

Try removing - "minimum_number_should_match": 2 . 尝试删除- "minimum_number_should_match": 2 It should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM