Creates a new index. To create an automatic index bound to a schema property use section "ON" of create index command or use as name the <class.property> notation. But assure to have created the schema for it before the index. See the example below.
Indexes can be:
CREATE INDEX <name> [ON <class-name> (prop-names)] <type> [<key-type>]
METADATA [{<json-metadata>}]
Where:
<class>.<property>
to create an automatic index bound to a schema property. In this case class is the class of the schema and property, is the property created into the class. Notice that in another case index name can't contain '.' symbolIf "ON" and key-type sections both exist database validate types of specified properties. And if types of properties not equals to types specified in key-type list, exception will be thrown.
List of key types can be used for creation manual composite indexes, but such indexes don't have fully support yet.
CREATE INDEX mostRecentRecords unique date
CREATE PROPERTY User.id BINARY
CREATE INDEX User.id UNIQUE
CREATE INDEX thumbsAuthor ON Movie (thumbs) unique;
CREATE INDEX thumbsAuthor ON Movie (thumbs by key) unique;
CREATE INDEX thumbsValue ON Movie (thumbs by value) unique;
CREATE PROPERTY Book.author STRING
CREATE PROPERTY Book.title STRING
CREATE PROPERTY Book.publicationYears EMBEDDEDLIST INTEGER
CREATE INDEX books ON Book (author, title, publicationYears) UNIQUE
You can create an index against the edge class if it's containing the begin/end date range of validity. This is a very common use case with historical graphs. Consider this File system example:
CREATE CLASS File EXTENDS V
CREATE CLASS Has EXTENDS E
CREATE PROPERTY Has.started DATETIME
CREATE PROPERTY Has.ended DATETIME
CREATE INDEX Has.started_ended ON Has (started, ended) NOTUNIQUE
And then you can retrieve all the edge that existed in 2014:
SELECT FROM Has Where started >= '2014-01-01 00:00:00.000' and ended < '2015-01-01 00:00:00.000'
To have the connected parent File:
SELECT outV() FROM Has Where started >= '2014-01-01 00:00:00.000' and ended < '2015-01-01 00:00:00.000'
To have the connected children Files:
SELECT inV() FROM Has Where started >= '2014-01-01 00:00:00.000' and ended < '2015-01-01 00:00:00.000'
Indexes by default ignore null values. For such reason queries against NULL value that use indexes return no entries.
If you want to index also null values set { ignoreNullValues : false }
as metadata. Example:
CREATE INDEX addresses ON Employee (address) notunique
METADATA {ignoreNullValues : false}