Dates range query do not return data

I can not understand why my dates range not working, it return empty data:

q.Paginate(
    q.Range(
      q.Match(q.Index('orders_by_dateFrom_desc')),
      q.Time('2021-06-16T10:00:00.000+03:00'),
      q.Time('2021-07-30T10:00:00.000+03:00'),
    )
  )

return:

{
  data: []
}

My index:

{
  ref: Index("orders_by_dateFrom_desc"),
  ts: 1619730807280000,
  active: true,
  serialized: true,
  name: "orders_by_dateFrom_desc",
  source: Collection("orders"),
  values: [{ field: ["data", "dateFrom"], reverse: true }, { field: "ref" }],
  partitions: 8
}

It work, query without conditions returns data,

q.Paginate(
  q.Match(q.Index('orders_by_dateFrom_desc')),
)

like:

{
  data: [
    [
      Time("2021-07-12T07:00:00Z"),
      Ref(Collection("orders"), "302461029804147211")
    ],
    [
      Time("2021-07-12T07:00:00Z"),
      Ref(Collection("orders"), "302461132720833038")
    ],
    [
      Time("2021-07-06T07:00:00Z"),
      Ref(Collection("orders"), "302461174707913227")
    ],
    [.....

in database dateFrom stores as Time:

dateFrom: Time("2021-06-16T07:00:00Z"),

What is not correct in my range query or index?

Range operates on the set in sorted order, so it starts at the beginning of the list and looks for the first boundary, Time('2021-06-16T10:00:00.000+03:00'). Once it finds a suitable starting point (either a matching entry, or where the next entry would be inside the range), then it starts looking for the second boundary, Time('2021-07-30T10:00:00.000+03:00'). It never finds the second boundary because the index is sorted in reverse order, so the result is an empty array.

Just change the order of the boundary values:

q.Paginate(
  q.Range(
    q.Match(q.Index('orders_by_dateFrom_desc')),
    q.Time('2021-07-30T10:00:00.000+03:00'),
    q.Time('2021-06-16T10:00:00.000+03:00')
  )
)
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.