elasticsearchsolr-boost

Difference between Weight and boost in Elasticsearch


I read about boosting in Elasticsearch. We can apply boosting at index or query time. Index time boosting is sort of static boosting and not suggested. Query time boosting is dynamic in nature. Query time boosting is good and preferred approach.

We can also add boosting to the fields. For example we are searching a term in multiple fields. We can boost a field to change the score of the document.

{
   "match":{"title":{"query":"test string","boost":10}}
},

I read about weight.

{
     "filter": { "match": { "test": "cat" } },
     "weight": 42
}

My understanding is weight applied on the fields in order to change the relevancy or score. Boost is applied to queries in order to change the relevancy or score.

But I am not sure about the difference in weight and boost.

Could someone correct me in understanding the difference between weight and boost with some example?


Solution

  • Fields are weighted against one another where as boosting is based on a given value within a field.

    Weights: Each field has a possible weight of 0 to 10, 10 being the most substantial weight. For Eg: If we want people to find the page they are looking for based on the query giving more importance to title, so we need to prioritize the title field. We can increase its weight so that it is more impactful than the other fields. If title had higher weight, people would find the document where this page is present in title at the top.

    {
      "search_fields":{ 
        "title": { 
          "weight": 10 
        }, 
        "subtitle": { 
          "weight": 5 
        }, 
        "description": { 
          "weight": 2 
        } 
      }, 
      "query": "Elastic" 
    }
    

    Here we are requesting elastic only to return 3 field i.e title, subtitle, description with the corresponding weights as 10,5,2.

    Boosts: Weights are applied to fields. Boosts are set-up on top of fields, but they are applied to field values. When boosting on number, date, or geolocation fields, you will need to define a function parameter and a factor. There are four types of function, depending on the boost: linear, exponential, gaussian, and logarithmic. The function and factor are used to compute half of the boosted relevance score, known as the boost value. The other half is the original document score. They combine to produce the overall document score, which governs the order of the result set

    {
      "query": "Elastic", 
      "boosts": {
        "is_elastic_query": [ 
          { 
            "type": "value", 
            "value": "true", 
            "operation": "multiply", 
            "factor": 10 
          } 
          ] 
      } 
    }
    

    Here we are assuming that is_elastic_query is a field with value either true of false. And we are boost it using value boost by factor 10 if the value is true.

    For details and examples on this please find the below link:

    https://www.elastic.co/guide/en/app-search/current/relevance-tuning-guide.html