Skip to content

dateField

const dateField: (input) => ElasticsearchFieldSpec;

Defined in: filters/elasticsearch.ts:53

Allow-list a public field as a date filter over a date field. A date preset needs the resolveDate you pass to buildQuery, and becomes a half-open range (gte/lt) with ISO-8601 instants.

Parameter Type
input { field: string; }
input.field string

ElasticsearchFieldSpec

import { buildQuery, dateField } from "@xtandard/lib/filters/elasticsearch";
// Your resolver turns the preset into instant bounds (this one is hard-coded).
const resolveDate = () => ({ start: new Date("2026-01-01T00:00:00Z"), end: new Date("2026-02-01T00:00:00Z") });
const { query } = buildQuery({
spec: { createdAt: dateField({ field: "createdAt" }) },
filters: [{ field: "createdAt", filter: { kind: "date", operator: "is", unit: "month", timeZone: "UTC", anchor: "2026-01-15T00:00:00" } }],
resolveDate,
});
// query → { bool: { filter: [
// { range: { createdAt: { gte: "2026-01-01T00:00:00.000Z" } } },
// { range: { createdAt: { lt: "2026-02-01T00:00:00.000Z" } } },
// ] } }