Field Operators

$boost

The $boost operator adjusts the relevance score contribution of a field match. This allows you to prioritize certain matches over others in the result ranking.

How Boosting Works

Search results are ordered by a relevance score that reflects how well each document matches the query. By default, all matching conditions contribute equally to this score. The $boost operator multiplies a match's score contribution by the specified factor.

  • Positive values greater than 1 increase the match's importance (e.g., $boost: 2.0 doubles the contribution)
  • Values between 0 and 1 decrease the match's importance
  • Negative values demote matches, pushing them lower in results

Use Cases

  • Prioritize premium content: Boost matches in title fields over body text
  • Promote featured items: Give higher scores to promoted products
  • Demote less relevant matches: Use negative boosts to push certain matches down

Compatibility

The $boost operator can be used with any field type since it modifies the score rather than the matching behavior.

Field TypeSupported
TEXTYes
U64/I64/F64Yes
DATEYes
BOOLYes
KEYWORDYes
FACETYes

Examples

// Boost matches in $should clauses to prioritize certain termsawait products.query({  filter: {    $must: {      inStock: true,    },    $should: [      { description: "premium", $boost: 10.0 },      { description: "quality", $boost: 5.0 },    ],  },});// Demote budget items with negative boostawait products.query({  filter: {    $must: {      category: "electronics",    },    $should: [      { name: "featured", $boost: 5.0 },      { description: "budget", $boost: -2.0 },    ],  },});
# Boost matches in $should clauses to prioritize certain termsproducts.query(filter={    "$must": {"inStock": True},    "$should": [        {"description": "premium", "$boost": 10.0},        {"description": "quality", "$boost": 5.0},    ],})# Demote budget items with negative boostproducts.query(filter={    "$must": {"category": "electronics"},    "$should": [        {"name": "featured", "$boost": 5.0},        {"description": "budget", "$boost": -2.0},    ],})
# Boost matches in $should clauses to prioritize certain termsSEARCH.QUERY products '{"$must": {"inStock": true}, "$should": [{"description": "premium", "$boost": 10.0}, {"description": "quality", "$boost": 5.0}]}'# Demote budget items with negative boostSEARCH.QUERY products '{"$must": {"category": "electronics"}, "$should": [{"name": "featured", "$boost": 5.0}, {"description": "budget", "$boost": -2.0}]}'
Loading search…