If I have a collection with 6 columns and define a sort order on one field (e.g. field: ["data", "amount"], reverse: true
), how do I get all fields in the collection when I query the index?
Map(
Paginate(
Match(Index("all_cars_order_by_amount_desc"))
),
Lambda("X", Get(Var("X")))
)
Returns the error “Ref or Set expected, Array provided.”
Hi @offradar,
Can you share the index definition you’re using? We need to know what you have set for your values
on the index since that’s what’s going to be returned.
By default, if you don’t set a values
attribute, Refs to the matching documents are returned. But it looks like you’re returning an array of some sort, which Get()
is unable to process.
Please run Get(Index("all_cars_order_by_amount_desc"))
and share the output here.
Thanks,
Cory
Thanks @Cory_Fauna
My query should be been:
Map(
Paginate(
Match(Index("all_cars_order_by_amount_desc"), [true, 'NY'])
),
Lambda("X", Get(Var("X")))
)
Index definition is like this:
terms: [
{
field: ["data", "available"]
},
{
field: ["data", "location"]
}
],
values: [
{
field: ["data", "salary"], reverse: true
},
{
field: ["ref"]
}
],
I would like to return all fields in the document so included ref in values
but I’m not sure how to format the query.
Ah, I see what’s happening. The index is returning an array of values; it’s returning both data.salary
as well as a ref to the document itself. If you only want to return the ref, and get access to the whole document, you need to select it from the array. Like so:
Map(
Paginate(
Match(Index("all_cars_order_by_amount_desc"), [true, 'NY'])
),
Lambda("x",Get(Select(1,Var("x"))))
)
Select()
will pull the item in position 1
(in this case, the ref) and pass that to Get()
, which will in turn return the entire document.
Thanks @Cory_Fauna that works for my query!