CreateIndex
CreateIndex( param_object )
CreateIndex( param_object )
CreateIndex( param_object )
CreateIndex( param_object )
create_index( param_object )
create_index param_object
CreateIndex( param_object )
CreateIndex( param_object )
Description
The CreateIndex
function adds a new index to the cluster 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.
FaunaDB builds the index asynchronously by scanning over relevant
documents of the source collection(s).
You can set As such, we recommend only using You can query whether an index is built:
If you see |
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
,values
, orpartitions
.
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.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
Object |
The param_object fields are described below. |
param_object
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
String |
The logical name of the index. Cannot be |
|
Array |
One or more source objects describing source collections and (optional) fields. |
|
Array |
Optional - An array of term objects describing the fields to be indexed. |
|
Array |
Optional - An array of value objects describing the fields to be covered. |
|
Boolean |
Set to |
|
Boolean |
Optional - If |
|
Boolean |
Optional - If |
|
Integer |
Optional - The number of sub-partitions within each term. |
|
Object |
Optional - Indicates who is allowed to read the index. |
|
Object |
Optional - This is user-defined metadata for the index. It is provided for the developer to store information at the index level. |
Returns
An object containing the metadata about the CreateIndex
operations.
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
Reference |
The reference is an automatically-generated, unique identifier within the database to the index that was created. |
|
String |
The logical name of the index created. |
|
Array |
The source and binding of the newly created index. |
|
Long |
The timestamp associated with the creation of the index. |
|
Boolean |
Indicates if the index has completed building and is fully operational. |
|
Long |
The timestamp associated with the creation of the index. |
Examples
The CreateIndex
operation builds an index on the collection "spells"
with the name "new-index".
curl https://db.fauna.com/ \
-u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
-d '{
"create_index": {
"object": { "name": "new-index", "source": { "collection": "spells" } }
}
}'
client.Query(
CreateIndex(
Obj("name", "new-index", "source", Collection("spells"))));
System.out.println(
client.query(
CreateIndex(
Obj(
"name", Value("new-index"),
"source", Collection(Value("spells"))
)
)
).get());
result, _ := client.Query(
f.CreateIndex(
f.Obj{"name": "new-index", "source": f.Collection("spells")},
),
)
fmt.Println(result)
client.query(
CreateIndex(
Obj("name" -> "new-index", "source" -> Collection("spells"))))
client.query(
q.create_index(
{"name": "new-index", "source": q.collection("spells")}
))
$client.query do
create_index name: 'new-index', source: collection('spells')
end
client.query(
CreateIndex(
Obj("name" => "new-index", "source" => Collection("spells"))
)
)
client.query(
q.CreateIndex(
{ name: "new-index", source: q.Collection("spells") }))
.then((ret) => console.log(ret))
HTTP/1.1 201 Created
{
"resource": {
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
}
{
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
{
ref: ref(id = "new-index", collection = ref(id = "indexes")),
ts: 1526674566835735,
active: false,
partitions: 8,
name: "new-index",
source: ref(id = "spells", collection = ref(id = "collections"))
}
map[ref:{new-index 0xc4201ef8e0 <nil>} ts:1509244540009619 active:false partitions:8 name:new-index source:{spells 0xc4201efb40 <nil>}]
{
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
{
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
{
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
{
"ref": { "@ref": "indexes/new-index" },
"class": { "@ref": "indexes" },
"ts": 1509244540009619,
"active": false,
"partitions": 8,
"name": "new-index",
"source": { "@ref": "classes/spells" }
}
{ ref: Ref(id=new-index, collection=Ref(id=indexes)),
ts: 1527275052756370,
active: false,
partitions: 8,
name: 'new-index',
source: Ref(id=spells, collection=Ref(id=collections)) }
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
documentation@fauna.com
Thank you for your feedback!