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
.
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
Collections created!
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
The following example adds some documents to the fruit
collection:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
Fruit items created!
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
Now let’s add some documents to the flowers
collection:
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
Flower items created!
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
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.
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
{
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 Python version of this example is not currently available.
The Shell version of this example is not currently available.
The following example searches the index fruit_and_flowers_search_by_color
for documents with the string red
in the color
field.
The C# version of this example is not currently available.
The Go version of this example is not currently available.
The Java version of this example is not currently available.
{
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' }
}
]
}
The Python version of this example is not currently available.
The Shell version of this example is not currently available.
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!