Skip to main content
The $boost operator adjusts the score contribution of a boolean clause. Use it to fine-tune how much weight specific conditions have in the overall relevance ranking. By default, all matching conditions contribute equally to a document’s relevance score. The $boost operator multiplies a clause’s score contribution by the specified factor:
  • Values greater than 1 increase importance (e.g., $boost: 5.0 makes the clause 5x more important)
  • Values between 0 and 1 decrease importance
  • Negative values demote matches, pushing them lower in results
The most common use case is boosting specific $should conditions to prioritize certain matches:
{
  $must: { category: "electronics" },
  $should: [
    { description: "premium", $boost: 10.0 },  // High priority
    { description: "featured", $boost: 5.0 },  // Medium priority
    { description: "sale" }                    // Normal priority (default boost: 1.0)
  ]
}
Documents matching “premium” rank significantly higher than those matching only “sale”. Negative boost values demote matches without excluding them entirely. This is useful when you want to push certain results lower without filtering them out:
{
  $must: { category: "electronics" },
  $should: {
    description: "budget",
    $boost: -2.0  // Push budget items lower in results
  }
}
Unlike $mustNot, which excludes documents entirely, negative boosting keeps documents in results but ranks them lower.

Examples

// Prioritize wireless and in-stock items
await products.query({
  filter: {
    $must: {
      name: "headphones",
    },
    $should: {
      description: "wireless",
      inStock: true,
      $boost: 5.0,
    },
  },
});

// Demote budget items without excluding them
await products.query({
  filter: {
    $must: {
      category: "electronics",
    },
    $should: {
      description: "budget",
      $boost: -1.0,
    },
  },
});