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.) The index may
return incomplete results until it is fully built and marked as active.
FaunaDB builds the index asynchronously by scanning over relevant
instance objects of the source class(es).
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
.
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 |
|
VarArgs |
One or more source objects describing source classes 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 |
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. |
|
VarArgs |
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 class "spells" with
the name "new-index".
curl https://db.fauna.com/ \
-u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
-d '{
"create_index": {
"object": { "name": "new-index", "source": { "class": "spells" } }
}
}'
client.Query(
CreateIndex(
Obj("name", "new-index", "source", Class("spells"))));
System.out.println(
client.query(
CreateIndex(
Obj(
"name", Value("new-index"),
"source", Class(Value("spells"))
)
)
).get());
result, _ := client.Query(
f.CreateIndex(
f.Obj{"name": "new-index", "source": f.Class("spells")},
),
)
fmt.Println(result)
client.query(
CreateIndex(
Obj("name" -> "new-index", "source" -> Class("spells"))))
client.query(
q.create_index(
{"name": "new-index", "source": q.class_expr("spells")}
))
$client.query do
create_index name: 'new-index', source: class_('spells')
end
client.query(
CreateIndex(
Obj("name" => "new-index", "source" => Class("spells"))
)
)
client.query(
q.CreateIndex(
{ name: "new-index", source: q.Class("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", class = ref(id = "indexes")),
ts: 1526674566835735,
active: false,
partitions: 8,
name: "new-index",
source: ref(id = "spells", class = ref(id = "classes"))
}
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, class=Ref(id=indexes)),
ts: 1527275052756370,
active: false,
partitions: 8,
name: 'new-index',
source: Ref(id=spells, class=Ref(id=classes)) }
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
documentation@fauna.com
Thank you for your feedback!