where_ends_with Query


  • 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, which is much faster.

  • In this page:


where_ends_with

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    // Call 'whereEndsWith' on the field
    // Pass the postfix to search by
    ->whereEndsWith("Name", "Lager")
    ->toList();

// Results will contain only Product documents having a 'Name' field
// that ends with any case variation of 'lager'
List<Product> products = session.Advanced
    .DocumentQuery<Product>()
     // Call 'WhereEndsWith'
     // Pass the document field and the postfix to search by
    .WhereEndsWith(x => x.Name, "Lager")
    .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with any case variation of 'lager'
from "Products"
where endsWith(Name, "Lager")

where_ends_with (case-sensitive)

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    // Pass 'exact: true' to search for an EXACT postfix match
    ->whereEndsWith("Name", "Lager", true)
    ->toList();

// Results will contain only Product documents having a 'Name' field
// that ends with 'Lager'
List<Product> products = session.Advanced
    .DocumentQuery<Product>()
     // Call 'WhereEndsWith'
     // Pass 'exact: true' to search for an EXACT postfix match
    .WhereEndsWith(x => x.Name, "Lager", exact: true)
    .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with 'Lager'
from "Products"
where exact(endsWith(Name, "Lager"))

Negate where_ends_with

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    // Call 'Not' to negate the next predicate
    ->not()
    // Call 'whereEndsWith' on the field
    // Pass the postfix to search by
    ->whereEndsWith("Name", "Lager")
    ->toList();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it
List<Product> products = session.Advanced
    .DocumentQuery<Product>()
     // Call 'Not' to negate the next predicate
    .Not
     // Call 'WhereEndsWith'
     // Pass the document field and the postfix to search by
    .WhereEndsWith(x => x.Name, "Lager")
    .ToList();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it
from "Products"
where (true and not endsWith(Name, "Lager"))