Indexes definition

An index definition is the indexes property of the Collection document definition with the following generalized structure:

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 ...
}

 

You can define any number of indexes for a collection in the indexes field and indexes are differentiated by their <indexName>. An index can have the following fields and requires that at least one term field or one value field 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 build 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.

queryable

Yes

Yes

Index query status:

true = The index can be used in queries while the index status field is Building.
false = The index can’t be used in queries while the index status field 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 index results.

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.

Examples

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!