---
title: "Ends-With Query"
description: "Filter RavenDB documents where a field value ends with a specified string using the EndsWith query operator."
url: "https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query"
version: "7.2"
language: "python"
---

# Ends-With Query

> Client language: Python. Also available for [C#](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.md), [PHP](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.php.md), [Node.js](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - You can query for documents having a field that ends with some specified string.
>
> - Unless explicitly specified, the string comparisons are case-insensitive by default.
>
> - **Note**:  
>   This postfix search causes the server to perform a full index scan.  
>   Instead, consider using a static index that indexes the field in reverse order  
>   and then query with a [prefix search](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/starts-with-query.python.md), which is much faster.
>
> - In this page:
>   - [where\_ends\_with](#where_ends_with)
>   - [where\_ends\_with (case-sensitive)](#where_ends_with-\(case-sensitive\))
>   - [Negate where\_ends\_with](#negate-where_ends_with)

## where\_ends\_with

### Query

```python
products = list(
  session.query(object_type=Product)
  # Call 'where_ends_with' on the field
  # Pass the postfix to search by
  .where_ends_with("Name", "Lager")
)

# Results will contain only Product documents having a 'Name' field
# that ends with any case variation of 'lager'
```

### RQL

```sql
from "Products"
where endsWith(Name, "Lager")
```

## where\_ends\_with (case-sensitive)

### Query

```python
products = list(
  session.query(object_type=Product)
  # Pass 'exact=True' to search for an EXACT postfix match
  .where_ends_with("Name", "Lager", exact=True)
)

# Results will contain only Product documents having a 'Name' field
# that ends with 'Lager'
```

### RQL

```sql
from "Products"
where exact(endsWith(Name, "Lager"))
```

## Negate where\_ends\_with

### Query

```python
products = list(
  session.query(object_type=Product)
  # Negate next statement
  .not_()
  # Call 'where_starts_with' on the field
  # Pass the prefix to search by
  .where_ends_with("Name", "Lager")
)
# Results will contain only Product documents having a 'Name' field
# that does NOT end with 'lager' or any other case variations of it
```

### RQL

```sql
from "Products"
where (true and not endsWith(Name, "Lager"))
```

## See also

- [Query overview](https://docs.ravendb.net/7.2/querying/overview.python.md)
- [Starts-With query](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/starts-with-query.python.md)
- [Full-text search](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/full-text-search.python.md)
- [Map indexes](https://docs.ravendb.net/7.2/indexes/map-indexes.python.md)
