vertexLabel

How to create a vertex label.

Synopsis

schema.vertexLabel('vertexLabel').
  [ partitionKey(propertyKey [, ... ]) ].
  [ clusteringKey(propertyKey[, ...]) ].
  [ ttl ].
  [ ifNotExists() ].
  [ index ].
  [ properties(property, ...).[ add() | drop() ]].
  [ cache().properties() | cache().bothE() ].
  [create() | drop() | describe() | exists() ]

Description

A vertex label specifies a type of vertex that can be stored in DSE Graph. A vertex label can have properties defined, a partition key, clustering key, indexes, cache, and a time-to-live (TTL) to determine the life cycle of an vertex.
CAUTION: DSE Graph limits the number of vertex labels to 200 per graph.
partitionKey

Specify a vertex label partition key. The value consists of one or more previously created property keys, with multiple property keys forming a composite partition key. The partitionKey and clusteringKey are used to specify a user-defined vertex id, identifying the partition storage location and order within the partition, respectively.

clusteringKey

Specify whether a vertex label can have any clustering keys. A clustering key can consist of one or more previously created property keys that specify how data will be stored within a partition.

ttl

Set a time-to-live for a vertex label.

ifNotExists
Creating a vertex label can check for lack of current existence with ifNotExists() before creating a new vertex label.
index

Set an index for a vertex label.

properties
Properties can be added to vertices and edges. A property key must be created prior to adding it to either type of element. Allowed characters for the name are alphabetical or underscore.

Examples

Create a vertexLabel meal_plan:
schema.vertexLabel('meal_plan').create()
Create a vertexLabel ingredient if the vertex label doesn't already exist:
schema.vertexLabel('ingredient').ifNotExists().create()
Add properties to a vertexLabel:
schema.vertexLabel('person').properties('nationality', 'age').add()

For indexes, see each index entry (edge index, property index, vertex index) in the Schema API.

Cache all properties for person vertices up to an hour (3600 seconds):
schema.vertexLabel('person').cache().properties().ttl(3600).add()
Enabling property cache causes index queries to use IndexCache for the specified vertex label.
Cache both incoming and outgoing made edges for person vertices up to a minute (60 seconds):
schema.vertexLabel('person').cache().bothE('made').ttl(60).add()
Create a time-to-live (TTL) for an vertexLabel of 60 seconds. Setting a TTL will expire all vertices inserted with the vertexLabel at the set TTL value:
schema.vertexLabel('shopping_list').ttl(60).create()
Note: DSE Graph sets TTL differently from the DSE database. The DSE database sets TTL per mutation (insertion or update) or can inherit a default value from the table schema. DSE Graph sets TTL per vertex label or edge label, and all vertices or edges will be affected by the TTL setting. DSE Graph cannot set TTL for an individual vertex or edge.
Check if a vertexLabel exists:
schema.vertexLabel('meal_plan').exists()
Get the schema creation command for a vertexLabel using the describe() command:
schema.vertexLabel('person').describe()
Remove a vertex label with the drop() command:
schema.vertexLabel('shopping_list').drop()
Remove a property nationality from a vertex label:
schema.vertexLabel('person').properties('nationality').drop()
Create a vertex label using sensor_id as a partition key.
schema().vertexLabel('fridge_sensor').partitionKey('sensor_id').create()
Create a vertex label with a partition key city_id and clustering key sensor_id.
schema().vertexLabel('fridge_sensor').partitionKey('city_id').clusteringKey('sensor_id').create()
Add a vertex using the schema from the last example:
graph.addVertex(label, 'fridge_sensor', 'city_id', 100, 'sensor_id', '60bcae02-f6e5-11e5-9ce9-5e5517507c66')
Create a vertex label using city_id and sensor_id as a composite partition key.
schema().vertexLabel('fridge_sensor').partitionKey('city_id', 'sensor_id').create()