kskaradzinski
kskaradzinski

Reputation: 5084

Boost values in query or in mapping

I can send boost value with query like

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": {
              "query": "quick brown fox",
              "boost": 2 
            }
          }
        }
      ]
    }
  }
}

but I can also set boost value in mapping

{
  "properties": {
    "title": {
      "type": "string",
      "boost": 2
    },
    "tags": {
      "type": "string"
    }
  }
}

And my question is. Which of this is faster while executing queries, to have boost in mapping or setting boost in query, or is it equaly fast.

Upvotes: 0

Views: 1244

Answers (1)

Christophe Schutz
Christophe Schutz

Reputation: 613

Index-time boosting is unrecommended by Elastic itself for multiple reasons :

  • Combining the boost with the field-length norm and storing it in a single byte means that the field-length norm loses precision. The result is that Elasticsearch is unable to distinguish between a field containing three words and a field containing five words.
  • To change an index-time boost, you have to reindex all your documents. A query-time boost, on the other hand, can be changed with every query.
  • If a field with an index-time boost has multiple values, the boost is multiplied by itself for every value, dramatically increasing the weight for that field.

See https://www.elastic.co/guide/en/elasticsearch/guide/current/practical-scoring-function.html for more details.

As for speed, I don't think it changes much at all, so you should probably stick to Query-time boosting which is the norm.

Upvotes: 1

Related Questions