Skip to main content

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:

EndsWith

List<Product> products = session
.Query<Product>()
// Call 'EndsWith' on the field
// Pass the postfix to search by
.Where(x => x.Name.EndsWith("Lager"))
.ToList();

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

EndsWith (case-sensitive)

List<Product> products = session
.Query<Product>()
// Pass 'exact: true' to search for an EXACT postfix match
.Where(x => x.Name.EndsWith("Lager"), exact: true)
.ToList();

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

Negate EndsWith

List<Product> products = session
.Query<Product>()
// Call 'EndsWith' on the field
// Pass the postfix to search by
.Where(x => x.Name.EndsWith("Lager") == false)
.ToList();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it