elasticsearch what is the difference between best_field and most_field

旧时模样 提交于 2020-05-26 12:03:47

问题


I already ready this article https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

but couldn't figure it out myself.

lets have these two queries:

first

GET blablabla/_search
{
  "query": {
    "multi_match": {
      "query": "games usa",
      "fields": ["title1", "title2"],
      "type": "best_fields"
    }
  }
}

second

get blablabla/_search
{
  "query" : {
    "multi_match": {
      "query": "games usa",
      "fields": ["title1", "title2"],
      "type": "most_fields"
    }
  }
}

I think the first query means:

get documetns that contain (games) or (usa) or (games and usa) words in either the title1 or the title2 fields.

However, I don't know what does the second one mean.

may i ask for help please?

(im on elasticsearch 2.2)


回答1:


Whenever search operation is performed in Elastic Search, relevance of each matched document is calculated.According to th documentation-

The relevance score of each document is represented by a positive floating-point number called the _score. The higher the _score, the more relevant the document.

As per your examples mentioned above

GET blablabla/_search
{
"query": {
"multi_match": {
  "query": "games usa",
  "fields": ["title1", "title2"],
  "type": "best_fields"
   }
  }
}

This query will find the documents which contain games AND/OR usa in title1 or title2 but _score will be calculated from single best matching field. For example-

  • if title1 contains games and title2 contains games usa in the same document, then _score will be the one from title2.
  • best_fields is most useful when you are searching for multiple words best found in the same field.

In most_fields:

GET blablabla/_search
{ 
"query" : {
"multi_match": {
  "query": "games usa",
  "fields": ["title1", "title2"],
  "type": "most_fields"
   }
  }
}

This query will find the documents which contain games AND/OR usa in title1 or title2 but _score will be calculated from the combination of all the fields. For example-

  • if title1 contains games and title2 contains games usa in the same document, then _score will be combination of scores from title1 and title2

Hope this helps




回答2:


A little remark for most_fields - it uses score from both fields. and divide it on fields count

In your example: ( Score from title1 + score from title2 ) / 2



来源:https://stackoverflow.com/questions/35393793/elasticsearch-what-is-the-difference-between-best-field-and-most-field

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