Indexes definition

Index definitions are a property of the Collection document definition.

The following is a generalized Index definition:

indexes: {
  <indexName>: {
    terms: [
      {
        field: "<fieldName>",
        mva: true | false
      },
        ... more terms ...
    ],
    values: [
      {
        field: "<fieldName>",
        order: asc | desc
        mva: true | false
      },
        ... more values ...
    ],
    queryable: <boolean>,
    status: <literal>
  },
    ... more indexes ...
}

The following table describes the indexes fields.

You can define any number of indexes and the name of an Index is its <indexName>. A defined Index requires that at least one term or one value to also be defined.

Property Optional Type Writeable Description

terms

Yes

Yes

Term definition list. A term defines exact match criteria. See terms.

values

Yes

Yes

Value definition list. A value describes a discrete or range value to match on. See values.

status

Yes

No

Index status:

Building = Index build underway. Indexing many documents takes time.
Complete = Index build completed.
Failed = Index build failed.

The index build process executes asynchronously so indexes can’t be built or rebuilt instantaneously. The status field reflects the build status.

queryable

Yes

Yes

Index query status:

true = Index can be used in queries while the index is building.
false = Index can’t be used in queries while the index is building.

terms

Terms are an Array of zero or more field definitions for document values that are used for equality comparisons during a search. If a given document doesn’t have values defined for all the terms, no index entry is created for that document.

The following document field types can be indexed as terms:

  • Boolean

  • Number

  • String

  • Date

  • Time

  • Arrays
    When an Array is indexed, an index entry is created for each of its elements.
    A null value is indexed only when part of an Array.

  • Document references
    A Document reference represents another document without storing the fields of the other document in the current document.

Properties

Every terms Array field definition is an Object:

Field Type Required Description

field

Yes

The document field path to use for searching. Dot notation is accepted.

mva

No

Multivalued attribute flag. This field is returned only if it is set by the user to true or false:

true = Create an index entry for every array element.
false = (default) Single terms array element.

Access nested terms fields using dot notation.

Example

terms: [
  { field: "name" },
  { field: "address.city" }
]

The document field name and the city field in the address field are used for searching.

values

Values are an Array of zero or more field definitions for document values that are used to order results from indexes.

When values are defined for the index, all documents are indexed including those that have a null value for the field.

Properties

Field Type Required Description

field

Yes

The document field path to use for searching. Dot notation is accepted.

order

No

The sort order for this field:

asc = (default) sort results in ascending order
desc = sort results in descending order

mva

No

Multivalued attribute flag:

true = Create an index entry for every array element. This field is returned only if it is set to true.
false = Single values array element.

Access nested values fields using dot notation.

Example

values: [
  { field: "price", order: "desc" },
  { field: "name" }
]

The document field price is sorted in descending order. When there are two or more equivalent prices, the name field sorts the equivalent price results by the name field.

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!