CreateIndex( param_object )
CreateIndex( param_object )
CreateIndex( param_object )
CreateIndex( param_object )
create_index( param_object )
CreateIndex( param_object )


The CreateIndex function adds a new index to the database with the specified parameters. After the transaction containing the CreateIndex is completed, the index is immediately available for reads. (The index may not be used in the transaction it was created, and it may not be created in the same transaction as its source collection(s).) The index may return incomplete results until it is fully built and marked as active. Fauna builds the index asynchronously by scanning over relevant documents of the source collection(s).

When an index is created, documents are immediately indexed if the associated collection contains up to 128 events (which include document creation, updates, and deletions). When an index contains all of a collection’s documents, including each document’s events, it is an "active" index.

For collections with more than 128 events (which include document creation, updates, and deletions), or those that use a wildcard in their source definition, indexing is handled by a background task, and you may have to wait a short period before the index returns values. Until the indexing task is complete, the index is an "inactive" index.

To check whether an index is "active", run the following query (replacing index_name with the name of the index that you want to check):

Select("active", Get(Index("index_name")))

If you see true in the output, the index is "active" and is ready for your queries. Otherwise, you should wait and check again later, until true appears in the output.

The length of the field values specified for the terms or values fields must not exceed 32k bytes. The maximum size of an index entry, which is comprised of the terms and values content (and some overhead to distinguish multiple fields), must not exceed 64k bytes. If an index entry is too large, the query that created/updated the index entry fails.

Updating index fields

  • It is possible to rename an index by updating its name field. Renaming an index changes its reference, but preserves inbound references to the index. Index data is not rebuilt.

  • If you update the unique field, it does not remove existing duplicated items from the index, but does prevent future duplicates from being added.

  • The fields of an index which may not be modified are terms and values.

Unique name required

The index name must be unique within the database. If you try to lookup an index by name and only create it if it does not exist, the operation might fail if another transaction created the index in the meantime.

Deleting an index

When an index is deleted, it becomes inaccessible, and its data is deleted asynchronously.


Argument Type Definition and Requirements


The param_object fields are described below.


Field Name Field Type Definition and Requirements


The logical name of the index. Cannot be events, sets, self, documents, or _.


A Collection reference, or an array of one or more source objects describing source collections and (optional) binding fields.


Optional - An array of Term objects describing the fields that should be searchable. Indexed terms can be used to search for field values, via the Match function. The default is an empty Array.


Optional - An array of Value objects describing the fields that should be reported in search results. The default is an empty Array. When no values fields are defined, search results report the indexed document’s Reference.


Optional - If true, maintains a unique constraint on combined terms and values. The default is false.


Optional - If true, writes to this index are serialized with concurrent reads and writes. The default is true.


Optional - Indicates who is allowed to read the index. The default is everyone can read the index.


Optional - This is user-defined metadata for the index. It is provided for the developer to store information at the index level. The default is an empty object having no data.


An object containing the metadata about the CreateIndex operations.

Field Name Field Type Definition and Requirements


The reference is an automatically-generated, unique identifier within the database to the index that was created.


The logical name of the index created.


The source and binding of the newly created index.


The timestamp, with microsecond resolution, associated with the creation of the index.


Indicates if the index has completed building and is fully operational.


The number of sub-partitions used by this index. This value can be 8 or 1:

  • 1 when unique is true.

  • 8 when the index has no terms.

  • 1 in all other cases.


The following query creates an index on the collection "spells" with the name "new-index":

        Obj("name", "new-index", "source", Collection("spells"))
ObjectV(ref: RefV(id = "new-index", collection = RefV(id = "indexes")),ts: LongV(1603756181200000),active: BooleanV(True),serialized: BooleanV(True),name: StringV(new-index),source: RefV(id = "spells", collection = RefV(id = "collections")),partitions: LongV(8))
result, err := client.Query(
			"name": "new-index",
			"source": f.Collection("decrepit_huts"),

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
map[active:true name:new-index partitions:8 ref:{new-index 0xc00016a0c0 0xc00016a0c0 <nil>} serialized:true source:{decrepit_huts 0xc00016a1b0 0xc00016a1b0 <nil>} ts:1603747135990000]
                "name", Value("new-index"),
                "source", Collection(Value("spells"))
{ref: ref(id = "new-index", collection = ref(id = "indexes")), ts: 1593464646510000, active: true, serialized: true, name: "new-index", source: ref(id = "spells", collection = ref(id = "collections")), partitions: 8}
    name: 'new-index',
    source: q.Collection('spells'),
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
  ref: Index("new-index"),
  ts: 1591996190530000,
  active: true,
  serialized: true,
  name: 'new-index',
  source: Collection("spells"),
  partitions: 8
result = client.query(
    "name": "new-index",
    "source": q.collection("spells")
{'ref': Ref(id=new-index, collection=Ref(id=indexes)), 'ts': 1592856422060000, 'active': True, 'serialized': True, 'name': 'new-index', 'source': Ref(id=spells, collection=Ref(id=collections)), 'partitions': 8}
    Obj("name" -> "new-index", "source" -> Collection("spells"))))
{name: "new-index", source: ref(id = "spells", collection = ref(id = "collections")), ts: 1594485038640000, ref: ref(id = "new-index", collection = ref(id = "indexes")), partitions: 8, serialized: true, active: true}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email

Thank you for your feedback!