Elasticsearch:constant_score查询与bool.filter查询 [英] Elasticsearch : constant_score query vs bool.filter query

查看:989
本文介绍了Elasticsearch:constant_score查询与bool.filter查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Elasticsearch获得完全匹配的结果(因此我不在乎在这里得分)

I am trying to achieve an exact match result using Elasticsearch (so I don't care about scoring here)

我看到有两种方法可以做到这一点:

I see that there are 2 ways to do this :

{
    "query" : {
        "constant_score" : {
            "filter" : {
                "term" : {
                    "exact_match_field" : "hello world !"
                }
            }
        }
    }
}

{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "exact_match_field": "hello world !"
        }
      }
    }
  }
}

两个工作都能给我想要的结果。它们之间有什么区别?

Both work and gives me the result I want. Whats the difference between them ? Are there performance benefits of using one vs the other ?

(我正在使用Elasticsearch V 5.6)

(I am using Elasticsearch V 5.6)

谢谢!

推荐答案

恒定分数查询为任何匹配的文档提供相等的分数,而与 TF之类的任何得分因素无关,IDF 等。当您不在乎文档是否匹配多少,而只是在文档是否匹配并且给出分数时,可以使用它。

Constant score query gives an equal score to any matching document irrespective of any scoring factors like TF, IDF etc. This can be used when you don't care whether how much a doc matched but just if a doc matched or not and give a score too, unlike filter.

constant_score查询采用boost参数,该参数设置为与其他查询组合时每个返回文档的分数。默认情况下,boost设置为1。

A constant_score query takes a boost argument that is set as the score for every returned document when combined with other queries. By default boost is set to 1.

如果您对下面的链接感兴趣,则会为您提供更多见识

If you are interested below link will give you more insight

< a href = https://www.compose.com/articles/elasticsearch-query-time-strategies-and-techniques-for-relevance-part-ii/ rel = nofollow noreferrer> https:// www。 compose.com/articles/elasticsearch-query-time-strategies-and-techniques-for-relevance-part-ii/

这篇关于Elasticsearch:constant_score查询与bool.filter查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆