python - 解释elasticsearch的minimum_should_match

标签 python elasticsearch

我对 Elasticsearch 查询非常陌生,我希望通过以下对我正在查看的现有源代码的查询得到一些澄清。

body["query"]["bool"]["should"] = [
    {"match": {"categories": {"query": raw_query, "operator": "and"}}},
    ....,
    ....,
    {"match": {"all": {"query": raw_query, "minimum_should_match": "50%" if keywords else "2<80%"}}}
]
body["query"]["bool"]["minimum_should_match"] = 1

我对minimum_should_match的理解是它指定了查询的最小匹配单词数。例如,对于以下内容,3 个单词中的任意 2 个 young , transformationEgyptian满足 description 的匹配字段。

"query":{
    "match":{
        "description":{
          "query" : "young transformation Egyptian",
          "minimum_should_match" : 2
        } 
    }
  }

从源码中我了解到"minimum_should_match": "50%"这意味着只要 raw_query 中的一半单词那么长与字段 all 中的内容匹配如果有keywords 。让我有点困惑的是2<80% 。我已经阅读了文档,但我仍然很困惑。

来自文档,https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html ,它给出了 3<90% 的示例并说:

if there are 1 to 3 clauses they are all required, but for 4 or more clauses only 90% are required.

clause到底是什么? ?我认为该条款是 every match在本例中是语句,但从源代码来看,它被放置在单个 match 中。条款。在这种情况下,它怎么可能有多个子句呢?我的理解显然是错误的。

我需要确认的最后一部分是:

body["query"]["bool"]["minimum_should_match"] = 1

因为它被放置在 should 之外,这是否意味着只有一个 match来自body["query"]["bool"]["should"]是必需的吗?

最佳答案

My understanding of minimum_should_match is that it specifies the number of minimum matching words to the query.

并非总是如此。这里,minimum_should_match 不适用于特定的全文查询,而是适用于 bool 查询,并控制应触发多少个 should 子句。

如果将 minimum_should_match 应用于特定的 match 查询,那么是的,它将控制应匹配的标记(单词)数量。

关于python - 解释elasticsearch的minimum_should_match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71257934/

相关文章:

api - 如何在 Elastic Search 中处理 "private"数据

python - 使用 Bulk-API 使用 Elasticsearch-py 将时间戳添加到 ElasticSearch

python - scikit-learn 中的 StratifiedKFold 与 KFold

python - python webdriver在chrome浏览器中的 Selenium 新标签

elasticsearch - 使用Sphinx进行多语言全文搜索

Elasticsearch 许可证.过期.功能安全状态 403

java - Logstash JDBC插件 - 并非所有字段都从oracle进入elasticsearch

python - 使用 django 在 python 中将 Model.Objects.all() 转换为 JSON

带有 Selenium 的 Python : Is it possible to refresh frame instead of the whole page?

python - 如何让 pyflakes 在 Windows 上运行?