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
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'
from "Products"
where endsWith(Name, "Lager")
where_ends_with (case-sensitive)
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'
from "Products"
where exact(endsWith(Name, "Lager"))
Negate where_ends_with
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
from "Products"
where (true and not endsWith(Name, "Lager"))