> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# $phrase

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 Type  | Supported |
| ----------- | --------- |
| TEXT        | Yes       |
| U64/I64/F64 | No        |
| DATE        | No        |
| BOOL        | No        |
| KEYWORD     | No        |
| FACET       | No        |

### Examples

<Tabs>
  <Tab title="TypeScript">
    ```ts theme={"system"}
    // 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,
          },
        },
      },
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"system"}
    # Simple phrase (terms must be adjacent)
    products.query(filter={"description": {"$phrase": "noise cancelling"}})

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

    # Prefix matching (last term can be partial)
    products.query(filter={"name": {"$phrase": {"value": "wireless head", "prefix": True}}})
    ```
  </Tab>

  <Tab title="Redis CLI">
    ```bash theme={"system"}
    # Simple phrase (terms must be adjacent)
    SEARCH.QUERY products '{"description": {"$phrase": "noise cancelling"}}'

    # With slop (allow terms between, not exact adjacency)
    SEARCH.QUERY products '{"description": {"$phrase": {"value": "wireless headphones", "slop": 2}}}'

    # Prefix matching (last term can be partial)
    SEARCH.QUERY products '{"name": {"$phrase": {"value": "wireless head", "prefix": true}}}'
    ```
  </Tab>
</Tabs>
