Difference between Weight and boost in Elasticsearch
Asked Answered
C

2

15

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?

Caligula answered 22/5, 2020 at 13:27 Comment(0)
E
6

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

Epilepsy answered 6/1, 2021 at 9:46 Comment(0)
C
12

1. Relevance Tuning in Elastic Search is changing how fields are weighted against one another or boosting relevance given a value within a field. Note: You must have at least two schema fields to tune relevance.

2. Weights are applied to fields. Boosts are set-up on top of fields, but they are applied to field values.

3. Weights

  • Each field has a possible weight of 0 to 10, 10 being the most substantial weight.

    curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search'
    -H 'Content-Type: application/json'
    -H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8'
    -d '{ "search_fields": { "title": { "weight": 10 }, "description": { "weight": 1 }, "states": { "weight": 2 } }, "query": "mountains" }'

Here we are asking to return only three fields within our results: title, description, and states. We are weighting each field: 10, 1, and 2, respectively.

4. Boosts

  • There are 4 kinds of Boosts. Use a boost to increase relevance.

    { "query" : { "dis_max" : { "queries" : [ { "match" : { "qualifications" : { "query" : "social media", "boost" : 2 } } }, { "match" : { "cover_letter" : "social media" } } ] } } }

Here we add a boost to a disjunction max query for job candidates who list "social media" in their resume. This example boosts the query match by 2 in the field "qualifications" compared to nothing being boosted if "social media" shows up in the cover_letter field.

In these examples, the weights are hard fixed to the fields no matter what, where the boost is hard fixed on the query "social media" but only if it matches inside the qualifications field. Hope this helps..

  1. Elastic Search doc on the matter
  2. A really good Boosting example including negative_boost, field_value_factor, and date based weight decay
  3. Other very useful links on the matter boost_1, boost_2, boost_3, boost_4, weight_1
Commute answered 5/1, 2021 at 18:18 Comment(1)
4 out of the 7 links in this answer are deadPermutation
E
6

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

Epilepsy answered 6/1, 2021 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.