Prioritizing a title match over content match
It is often required that you conduct a search on multiple fields, but then, it's also important to make sure that certain field matches are prioritized over the others to make the search results more relevant.
If we are using a multifield search, it is a good idea to use a multisearch query. Here, you can give multiple fields and also prioritize on some of the fields. An example of this is as follows:
{ "query": { "multi_match": { "query": "white elephant", "fields": [ "Title^10", "Content" ] } } }
Here, we search on both the Title
and Content
field and prioritize the Title
field match over the Content
field match. The ^10
parameter next to the Title
field name makes sure that the match over the Title
field is given 10 times more relevance.