Boosting in Elasticsearch

后端 未结 2 1820
甜味超标
甜味超标 2021-02-08 03:32

I am new to elasticsearch. In elasticsearch we can use the term boost in almost all queries. I understand it\'s used for modify score of documents. But i can\'t find actual use

相关标签:
2条回答
  • 2021-02-08 04:19

    Query time boost allows you to give more weight to one query than to another. For instance, let's say you are querying the title and body fields for "Quick Brown Fox", you could write it as:

    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": "Quick Brown Fox"
              }
            },
            {
              "match": {
                "body": "Quick Brown Fox"
              }
            }
          ]
        }
      }
    }
    

    But you decide that you want the title field to be more important than the body field, which means you need to boost the query on the title field by (eg) 2:

    {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "query": "Quick Brown Fox",
                  "boost": 2
                }
              }
            },
            {
              "match": {
                "body": "Quick Brown Fox"
              }
            }
          ]
        }
      }
    }
    

    (Note how the structure of the match clause changed to accommodate the boost parameter).

    The boost value of 2 doesn't double the _score exactly - the scores go through a normalization process. So you should think of boost as make this query clause relatively more important than the other query clauses.

    My doubt is if i use boost values in some queries. will it affect final score of search

    Yes it does, but you shouldn't rely on the actual value of _score anyway. Its only purpose is to allow Elasticsearch to decide which documents are most relevant to this query. If the query changes, the scores change.

    Re index time boosting: don't use it. It's inflexible and error prone.

    0 讨论(0)
  • 2021-02-08 04:32

    Boost at query time won't modify your index. It only applies boost factor on fields when searching.

    I prefer boost at query time as it's more flexible. If you need to change your boost rules and you had set it at index time, you will probably need to reindex.

    0 讨论(0)
提交回复
热议问题