ElasticGraph Query API: DateTime Filtering
Try these example queries by visiting the GraphiQL UI after booting locally.
Copied!
$ curl -s https://block.github.io/elasticgraph/dc.yml | docker compose -f - up --pull always
ElasticGraph supports three different date/time types:
Date
- A date, represented as an ISO 8601 date string.
Example:
"2024-10-15"
. DateTime
- A timestamp, represented as an ISO 8601 time string.
Example:
"2024-10-15T07:23:15Z"
. LocalTime
- A local time such as
"23:59:33"
or"07:20:47.454"
without a time zone or offset, formatted based on the partial-time portion of RFC3339.
All three support the standard set of equality and
comparison predicates. When using comparison
predicates to cover a range, it’s usually simplest to pair gte
with lt
:
Copied!
query Find2024Shows {
artists(filter: {
tours: {anySatisfy: {shows: {anySatisfy: {
startedAt: {
gte: "2024-01-01T00:00:00Z"
lt: "2025-01-01T00:00:00Z"
# Using gte/lt to fully cover the range is simpler than gte/lte:
# gte: "2024-01-01T00:00:00Z"
# lte: "2024-12-31T23:59:99.999Z"
# ...and simpler than gt/lt:
# gt: "2023-12-31T23:59:99.999Z"
# lt: "2025-01-01T00:00:00Z"
}
}}}}
}) {
nodes {
name
tours {
shows {
venue {
id
}
startedAt
}
}
}
}
}
In addition, DateTime
fields support one more filtering operator:
timeOfDay
- Matches records based on the time-of-day of the DateTime values.
When
null
or an empty object is passed, matches no documents.
For example, you could use it to find shows that started between noon and 3 pm on any date:
Copied!
query FindEarlyAfternoonShows {
artists(filter: {
tours: {anySatisfy: {shows: {anySatisfy: {
startedAt: {
timeOfDay: {
timeZone: "America/Los_Angeles"
gte: "12:00:00"
lt: "15:00:00"
}
}
}}}}
}) {
nodes {
name
tours {
shows {
venue {
id
}
startedAt
}
}
}
}
}