[英]How elasticsearch decides must and filter terms in same query?
The following query includes must and filter contexts in same query.以下查询包括同一查询中的必须和过滤上下文。
GET /_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Search" }},
{ "match": { "content": "Elasticsearch" }}
],
"filter": [
{ "term": { "status": "published" }}
]
}
}
}
if there are some documents that matches with must logic but not matches with filer logic, so I am getting no result?如果有一些文档与必须逻辑匹配但与文件管理器逻辑不匹配,那么我没有得到任何结果? Is filter most important?过滤器最重要吗? How works this query order?这个查询顺序是如何工作的? First must logic and then filter logic?首先必须逻辑,然后过滤逻辑?
Here it will match all the conditions of MUST & FILTERS.在这里它将匹配 MUST & FILTERS 的所有条件。 You can see MUST & FILTER something like AND query.您可以看到 MUST & FILTER 之类的 AND 查询。 So the query will go like title="search" AND content="Elasticsearch" AND status="published"
.所以查询将 go 像title="search" AND content="Elasticsearch" AND status="published"
。
The only difference is MUST contributes to scoring where FILTER is not.唯一的区别是必须有助于在 FILTER 没有的情况下进行评分。
So if you hit same query like below,因此,如果您点击如下相同的查询,
GET /_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Search" }},
{ "match": { "content": "Elasticsearch" }},
{ "term": { "status": "published" }}
]
}
}
}
You will see the different _score
value with same result.您将看到具有相同结果的不同_score
值。
So simple is if you want to ignore scoring just use filter.很简单,如果您想忽略评分,只需使用过滤器。
Mostly filters are use with conditions like <
, >
, <=
, >=
, =
or where you don't want score.大多数情况下,过滤器用于<
、 >
、 <=
、 >=
、 =
等条件或您不想要得分的地方。
Note : Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.注意:经常使用的过滤器将被 Elasticsearch 自动缓存,以加快性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.