Skip to main content
The $phrase operator matches documents where terms appear in a specific sequence. Unlike a simple multi-term search that finds documents containing all terms anywhere, phrase matching requires the terms to appear in the exact order specified.

Simple Form

In its simplest form, $phrase takes a string value and requires the terms to appear adjacent to each other in order:
{ $phrase: "wireless headphones" }
This matches “wireless headphones” but not “wireless bluetooth headphones” or “headphones wireless”.

Slop Parameter

The slop parameter allows flexibility in phrase matching by permitting other words to appear between your search terms. The slop value represents the maximum number of position moves allowed to match the phrase. For example, with slop: 2:
  • “wireless headphones” matches (0 moves needed)
  • “wireless bluetooth headphones” matches (1 move: “headphones” shifted 1 position)
  • “wireless bluetooth overhead headphones” matches (2 moves)
  • “wireless bluetooth noise-cancelling headphones” does NOT match (requires 3 moves)
A slop of 0 requires exact adjacency (the default behavior).

Prefix Parameter

The prefix parameter allows the last term to match as a prefix. This is useful for autocomplete scenarios where users might not complete the final word:
description: { $phrase: { value: "wireless head", prefix: true } }
This matches “wireless headphones”, “wireless headset”, etc. Note: You can use either slop or prefix, but not both in the same query.

Compatibility

Field TypeSupported
TEXTYes
U64/I64/F64No
DATENo
BOOLNo

Examples

// Simple phrase (terms must be adjacent)
await products.query({
  filter: {
    description: {
      $phrase: "noise cancelling",
    },
  },
});

// With slop (allow terms between, not exact adjacency)
await products.query({
  filter: {
    description: {
      $phrase: {
        value: "wireless headphones",
        slop: 2,
      },
    },
  },
});

// Prefix matching (last term can be partial)
await products.query({
  filter: {
    name: {
      $phrase: {
        value: "wireless head",
        prefix: true,
      },
    },
  },
});