Creating a graph in the Gremlin console
Creating a graph in the Gremlin Console.
DataStax Studio creates a graph automatically for each connection that is created. In Gremlin console, a graph must be manually created. In addition to creating the graph, a graph traversal must be aliased to the graph in order to run queries.
Procedure
- Start the Gremlin console.
-
Create a simple graph with default settings to hold the data.
gremlin> system.graph('food').create()
==>null
Note: This command is not available if a graph traversal is aliased with the:remote config alias g some_graph.g
command. In order to access the system command, reset the alias with:remote config alias reset
-
Create a graph with non-default replication, systemReplication, and configuration settings:
system.graph('food2'). replication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3 }"). systemReplication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3 }"). option("graph.schema_mode").set("Production"). option("graph.allow_scan").set("false"). option("graph.default_property_key_cardinality").set("multiple"). option("graph.tx_groups.*.write_consistency").set("QUORUM"). create()
CAUTION:For graphs created in multi-datacenter clusters, the Cassandra settings must useNetworkTopologyStrategy
and a replication factor greater than one. If the graph is created with a replication setting ofSimpleStrategy
and a replication factor of 1, the graph data will be stored across the multiple datacenters rather than localizing the data in the graph datacenter.The default replication strategy for a multi-node or multi-datacenter graph isNetworkTopologyStrategy
, whereas for a single node, the replication strategy will default toSimpleStrategy
. The number of nodes will determine the default replication factor:number of nodes per datacenter graph_name replication factor graph_name_system replication factor 1-3 number of nodes per datacenter number of nodes per datacenter greater than 3 3 5 -
On the remote Gremlin Server, set the alias for the graph traversal
g
to the graph traversal specified infood
. To run traversals, the graph traversal must be aliased to a graph.gremlin> :remote config alias g food.g
==>g=food.g
-
A list of all graphs can be retrieved with the following command:
gremlin> system.graphs()
==> food ==> test