Missing results in index with binding

I have created an Index of events with terms for an event type and a day on which that event occurred (binding). The collection has quite some documents, around 13.000.

The results come in correctly for dates prior to creating the index, but no results are shown for the date of today. While the data is present in the collection, so I would expect to see those results come back as well.

What could be the issue here?

Index used:

{
  ref: Index("event_value_by_type_and_day"),
  ts: 1662133101695000,
  active: true,
  serialized: true,
  name: "event_value_by_type_and_day",
  source: {
    collection: Collection("events"),
    fields: {
      eventValueNumber: Query(
        Lambda(
          "document",
          ToDouble(Select(["data", "eventValue"], Var("document")))
        )
      ),
      day: Query(
        Lambda(
          "document",
          ToDate(Epoch(Select("ts", Var("document")), "microsecond"))
        )
      )
    }
  },
  terms: [
    {
      field: ["data", "event"]
    },
    {
      binding: "day"
    }
  ],
  values: [
    {
      binding: "eventValueNumber"
    }
  ],
  partitions: 1
}

Document that should show up, but doesn’t

{
  "ref": Ref(Collection("events"), "341768519209189969"),
  "ts": 1662194708960000,
  "data": {
    "event": "TEMP",
    "eventValue": "18.5",
  }
}

How did you create your “events” collection? I ask because that is a reserved collection name. When you tried to create the collection, you should have received the error:

> CreateCollection({ name: "events" })
Error: validation failed
{
  errors: [
    {
      position: [
        'create_collection'
      ],
      code: 'validation failed',
      description: 'document data is not valid.',
      failures: [
        {
          field: [
            'name'
          ],
          code: 'reserved name',
          description: 'Invalid name events. Reserved names: sets, _, events, self, instances.'
        }
      ]
    }
  ]
}

My bad, I changed the collection name for the sake of simplicity. The collection actually had a longer name.

You haven’t shown the query that you are using. Here’s what I’ve done:

> CreateCollection({ name: "evts" })
{
  ref: Collection("evts"),
  ts: 1662480417280000,
  history_days: 30,
  name: 'evts'
}

> CreateIndex({
  name: "event_value_by_type_and_day",
  source: {
    collection: Collection("evts"),
    fields: {
      eventValueNumber: Query(
        Lambda(
          "document",
          ToDouble(Select(["data", "eventValue"], Var("document")))
        )
      ),
      day: Query(
        Lambda(
          "document",
          ToDate(Epoch(Select("ts", Var("document")), "microsecond"))
        )
      )
    }
  },
  terms: [
    {
      field: ["data", "event"]
    },
    {
      binding: "day"
    }
  ],
  values: [
    {
      binding: "eventValueNumber"
    }
  ],
})
{
  ref: Index("event_value_by_type_and_day"),
  ts: 1662480546450000,
  active: true,
  serialized: true,
  name: 'event_value_by_type_and_day',
  source: {
    collection: Collection("evts"),
    fields: {
      eventValueNumber: Query(Lambda("document", ToDouble(Select(["data", "eventValue"], Var("document"))))),
      day: Query(Lambda("document", ToDate(Epoch(Select("ts", Var("document")), "microsecond"))))
    }
  },
  terms: [ { field: [ 'data', 'event' ] }, { binding: 'day' } ],
  values: [ { binding: 'eventValueNumber' } ],
  partitions: 1
}

> Create(Collection("evts"), { data: { "event": "TEMP", "eventValue": "18.5", }})
{
  ref: Ref(Collection("evts"), "342068171927192064"),
  ts: 1662480480040000,
  data: { event: 'TEMP', eventValue: '18.5' }
}

> Paginate(
  Match(
    Index("event_value_by_type_and_day"),
    ["TEMP", ToDate(Now()) ]
  )
)
{ data: [ 18.5 ] }

It looks like the index is working correctly, but your query may be incorrect.