Index definitions

See Indexes

Defines an index.

An index stores, or covers, specific document field values for quick retrieval. Using indexes can significantly improve query performance and reduce costs, especially for large datasets.

You include index definitions in a collection schema.

Syntax

index <indexName> {
  [terms [<term> . . .]]
  [values [<value> . . .]]
}

Name

indexName String Required

Unique index name.

Properties

Property Type Required Description

terms

Array of field accessors

Yes, if values is not defined.

Fields used for exact match searches.

Supports dot notation and bracket notation. You can only index persistable field values.

Use mva() to index an Array field’s values.

values

Array of field accessors

Yes, if terms is not defined.

Fields used for sorting and range searches.

Supports dot notation and bracket notation. You can only index persistable field values.

Use mva() to index an Array field’s values.

Use asc() or desc() to sort results in respective ascending or descending order. Defaults to asc (ascending).

Index document relationships

Examples

collection Product {
  ...
  index byName {
    terms [.name]
    values [desc(.stock), desc(mva(.productTypes))]
  }
  ...
}

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!