Hi,
I have a Collection that has documents where one field is an array. Now I want to create an index containing the documents where the number of elements in this array is larger than zero.
This is how I’m trying to create the index:
CreateIndex({
name: "eventsWithResults",
source: {
collection: Collection("events"),
fields: {
has_results: Query(
Lambda(
"document",
GT(Count(Select(["data", "results"], Var("document"), [])), 0)
)
)
}
},
terms: [{ binding: "has_results" }],
values: [
{ field: ["data", "time"], reverse: true },
{ field: ["data", "results", "score"], reverse: true },
{ field: ["ref"] }
]
})
However, I’m getting the error message that the binding is not a “pure unary function”.
A document with results (i.e. one that should be part of the index) looks like this:
{
"ref": Ref(Collection("events"), "340186818667348563"),
"ts": 1660686283635000,
"data": {
"time": "2022-07-24T01:05:19Z",
"eventnumber": "14485",
"results": [
{
"status": "Pending",
"score": 0.901
},
{
"status": "Final",
"score": 1.03
},
]
}
}
And a document without results (and thus should be excluded from the index) will look like this:
{
"ref": Ref(Collection("events"), "340186818538373714"),
"ts": 1660686282052000,
"data": {
"time": "2022-07-24T01:05:19Z",
"eventnumber": "14485",
"results": []
}
}