elasticsearch what is the difference between best_field and most_field
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
containsgames
andtitle2
containsgames usa
in the same document, then_score
will be the one fromtitle2
. 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
containsgames
andtitle2
containsgames usa
in the same document, then_score
will be combination of scores fromtitle1
andtitle2
Hope this helps
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