Elasticsearch : constant_score query vs bool.filter query

你。 提交于 2020-04-10 08:40:11

问题


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 !"
                }
            }
        }
    }
}

or

{
  "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 ?

(I am using Elasticsearch V 5.6)

Thanks !


回答1:


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.

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

https://www.compose.com/articles/elasticsearch-query-time-strategies-and-techniques-for-relevance-part-ii/



来源:https://stackoverflow.com/questions/51142871/elasticsearch-constant-score-query-vs-bool-filter-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!