Closed jcsco closed 1 year ago
Nevermind. I flipped the order of MatchFunc and Where clause and it is quick now. Maybe this behavior needs to be documented.
docs, err := db.FindAll(
clover.NewQuery(eventCollection).MatchFunc(func(doc *clover.Document) bool {
for _, v := range doc.ToMap() {
val, ok := v.(string)
if !ok {
continue
}
if val == value {
return true
}
}
return false
}).Where(clover.Field("eventTimestamp").GtEq(start).And(clover.Field("eventTimestamp").LtEq(end))).Sort(clover.SortOption{Field: "eventTimestamp", Direction: 1}))
I'm searching for a field in all documents within a given time range. Currently, my approach is to use MatchFunc to search in all fields of the document and added a where clause before it to specify the time range. I realize I could check the timestamp range within the MatchFunc but that wouldn't benefit from the indexing. Any suggestions to improve query performance?
My dataset is one million documents and the time field is an integer and is indexed.
I'm trying the following query but it still takes 30 secs.