Filter an Index by Time range

I’m trying to create an Index as follow

CreateIndex({
  name: "grabs_serch_by_adv_status_range_published_at",
  source: Collection("grabs"),
  terms: [
    {
      field: ["data", "adv"]
    },
    {
      field: ["data", "status"]
    }
  ],
  values: [
    {
      field: ["data", "destination", Time("max_delivery_date")]
    },
    {
      field: ["data", Time("published_at")],
      reverse: true
    },
    {
      field: ["ref"]
    }
  ]
})

But I get this error:

    "code": "invalid argument",
    "description": "Cannot cast 'max_delivery_date' to a time."

I want to later query the Index with this query:

Paginate(Range(Match(Index("grabs_serch_by_adv_status_range_published_at"), "product", "published"), Now(), []))

How can I filter a range using the Now() function?

max_delivery_date is in the format 2022-01-30T23:00:00.000Z

You have to use an index binding to generate index data based on document data:

Something like this:

CreateIndex({
  name: "grabs_serch_by_adv_status_range_published_at",
  source: {
    collection: Collection("grabs"),
    fields: {
      max_delivery_date_time: Query(
        Lambda(
          "doc",
          Time(Select(["data", "destination", "max_delivery_date"], Var('doc')))
        )
      ),
      published_at_time: Query(
        Lambda(
          "doc",
          Time(Select(["data", "published_at"], Var('doc')))
        )
      )
    }
  },
  terms: [
    {
      field: ["data", "adv"]
    },
    {
      field: ["data", "status"]
    }
  ],
  values: [
    { binding: "max_delivery_date_time" },
    { binding: "published_at_time", reverse: true },
    {
      field: ["ref"]
    }
  ]
})
2 Likes

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