FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date. Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard. For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions. |
Multi-collection indexes
Overview
A multi-collection index is an index which includes documents from more than one collection.
Indexes which cover multiple collections may be less performant than those which cover a single index. If possible, it’s a better practice to organize your collections and queries so that multi-collection indexes are not necessary. |
Example
For demonstration purposes, let’s create two collections named fruit
and flowers
.
Collections created!
The following example adds some documents to the fruit
collection:
Fruit items created!
Now let’s add some documents to the flowers
collection:
Flower items created!
To make these two collections searchable by their color
field, we can
create an index which specifies both collections in the source
field
and color
in the terms
field.
{
ref: Index("fruit_and_flowers_search_by_color"),
ts: 1642632647330000,
active: false,
serialized: true,
name: "fruit_and_flowers_search_by_color",
source: [Collection("fruit"), Collection("flowers")],
terms: [
{
field: ["data", "color"]
}
],
partitions: 1
}
The following example searches the index fruit_and_flowers_search_by_color
for documents with the string red
in the color
field.
{
data: [
{
ref: Ref(Collection("flowers"), "1"),
ts: 1648232012790000,
data: { type: 'rose', color: 'red' }
},
{
ref: Ref(Collection("fruit"), "1"),
ts: 1648232012610000,
data: { type: 'apple', color: 'red' }
},
{
ref: Ref(Collection("flowers"), "3"),
ts: 1648232012790000,
data: { type: 'carnation', color: 'red' }
}
]
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!