我对 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
, transformation
和Egyptian
满足 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/