I have an index that returns the necessary values to the frontend:
CreateIndex({
name: "all_blogs_by_status",
source: Collection("Blog"),
terms: [
{
field: ["data", "status"]
}
],
values: [
{
field: ["ref", "id"]
},
{
field: ["data", "title"]
},
{
field: ["data", "slug"]
},
{
field: ["data", "image"]
},
{
field: ["data", "type"]
},
{
field: ["data", "answered"]
},
{
field: ["data", "tags"]
},
{
field: ["data", "body"]
}
]
})
The documents looks like this:
{
title: "Test 3",
slug: "test-3",
image: "some-image",
type: "blog",
answered: false,
tags: ["test tag 1", "test tag 2", "test tag 3"],
status: "published",
body: "# test post 1",
}
Calling the index like this:
const { data }: any = await client.query(
q.Map(
q.Paginate(q.Match(q.Index("all_blogs_by_status"), "published")),
q.Lambda("post", q.Var("post"))
)
);
The result is this:
{
data: [
[
'321165580971278848',
'Test 1',
'test-1',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 1',
'# test post 1'
],
[
'321165580971278848',
'Test 1',
'test-1',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 2',
'# test post 1'
],
[
'321165580971278848',
'Test 1',
'test-1',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 3',
'# test post 1'
],
[
'321165580975473152',
'Test 2',
'test-2',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 1',
'# test post 1'
],
[
'321165580975473152',
'Test 2',
'test-2',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 2',
'# test post 1'
],
[
'321165580975473152',
'Test 2',
'test-2',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 3',
'# test post 1'
],
[
'321165580979667456',
'Test 3',
'test-3',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 1',
'# test post 1'
],
[
'321165580979667456',
'Test 3',
'test-3',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 2',
'# test post 1'
],
[
'321165580979667456',
'Test 3',
'test-3',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 3',
'# test post 1'
],
[
'321165580981764608',
'Test 4',
'test-4',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 1', # post 4 tag 1
'# test post 1'
],
[
'321165580981764608',
'Test 4',
'test-4',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 2', # post 4 tag 2
'# test post 1'
],
[
'321165580981764608',
'Test 4',
'test-4',
'https://images.unsplash.com/photo-1497215728101-856f4ea42174?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80',
'blog',
false,
'test tag 3', # post 4 tag 3
'# test post 1'
]
]
}
As you can see the index returns the same documents as the amount of items in the tags array.
Couldnt find any examples on how to return the index with the tags array as an array in each index result.
How would I make this work?
Feel free to formulate the question better for the future people who needs this answered, if needed. Thanks!