Indexes

Indexes allow for the organization and retrieval of documents by attributes other than their Reference. They act as a lookup table that improves the performance of finding documents: instead of reading every single document to find the one(s) that you are interested in, you query an index to find those documents.

See Limits for details on concurrent index builds and transaction limits. See the CreateIndex reference page for limitations on what an index may be named.

Source

When you create an index, you specify its source, which is one or more collections of documents. Once the index is active, any query that creates, updates, or deletes a document in the source collection(s) causes the index to be updated.

Terms

An index can specify terms: these are zero or more values from indexed documents that help you to find specific documents. terms are comparable to column=value predicates in an SQL WHERE clause. For example, if your documents contain a name field, you can define terms to include that field, and then you can find all of the documents that match a specific name.

When an index has one or more terms, the index is partitioned by the terms, allowing Fauna to efficiently scale indexes.

When a document is indexed, and all of the index’s defined terms evaluate to null, no index entry is stored for the document.

Values

An index can specify values: these are zero or more values returned for each index entry that matches the terms when you query the index. values are comparable to the SQL SELECT clause.

values are also how indexes are sorted: each field value in values is sorted lexically according to the field’s type, and the order can be inverted by specifying reverse.

Each index entry records the Reference of each document involved in the index. When no values are specified, the index returns the Reference for each matching index entry. When one or more values are specified, only those values are returned.

When a document is indexed, and all of the index’s defined values evaluate to null, no index entry is stored for the document.

Collection index

An index with no terms and values specified is known as a collection index: searching for specific documents is not possible, and all documents within the collection are included in the result set, and are sorted by their reference in ascending order.

Unique

You can specify that an index is unique. This means that, for the defined terms and values, the index contains only one entry for a document having those specific terms and values. As a result, creating or updating a document to have the same terms and values as an existing document would cause an error.

For more information about indexes, see the API Reference.

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!