class TimestampFilterTimestamp filter for date/time-based searches.
Important: In Redis, there is no separate "timestamp" field type. Timestamps are stored as NUMERIC fields containing Unix epoch timestamps (seconds since Jan 1, 1970 UTC).
This filter class is a convenience wrapper that:
When defining your metadata schema, use type: "numeric" for timestamp fields:
const schema: MetadataFieldSchema[] = [
{ name: "created_at", type: "numeric", options: { sortable: true } }
];Discriminator property for type-safe filter identification. Each filter type has a unique filterType value.
Combine this filter with another using AND logic.
In RediSearch, AND operations are represented by space-separated conditions
within parentheses: (condition1 condition2)
Combine this filter with another using OR logic.
In RediSearch, OR operations are represented by pipe-separated conditions
within parentheses: (condition1|condition2)
Converts the filter expression to a RediSearch query string.
Creates a builder object for constructing timestamp filters.
// Filter by exact date
const filter = new TimestampFilter("created_at", "eq", new Date("2023-01-01"));
// Generates: @created_at:[1672531200 1672531200]
// Filter for dates after a specific time
const filter = new TimestampFilter("created_at", "gt", new Date("2023-06-01"));
// Generates: @created_at:[(1685577600 +inf]
// Filter for dates in a range
const filter = new TimestampFilter(
"created_at",
"between",
[new Date("2023-01-01"), new Date("2023-12-31")]
);
// Generates: @created_at:[1672531200 1703980800]
// Using epoch timestamps directly
const filter = new TimestampFilter("updated_at", "gte", 1672531200);
// Using convenience methods
const filter = Timestamp("created_at").gt(new Date("2023-01-01"));
const filter2 = Timestamp("updated_at").between(
new Date("2023-01-01"),
new Date("2023-12-31")
);