Getting started with gremlin
Installation of Gremlin Console
As a prerequisite, Java 8 is required for the Gremlin Console to run. Ensure that it is installed prior to moving forward with the following steps.
Download the console, unpackage it and start it:
$ unzip apache-gremlin-console-x.y.z-bin.zip $ cd apache-gremlin-console-x.y.z $ bin/gremlin.sh \,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: tinkerpop.tinkergraph gremlin>
If on Windows, there is an included
gremlin.bat file that can be used to start the console.
To learn more about Gremlin Console, please read TinkerPop’s tutorial which discusses it’s usage in greater detail.
Using the Toy Graphs
The TinkerPop “toy graphs” make it possible to quickly try out some basic features of Gremlin. These graphs are pre-built and packaged with the Gremlin Console. The most commonly used “toy graphs” are “Modern” and “The Crew”. When asking questions on StackOverflow or the Gremlin Users mailing list it is often useful to frame questions in the context of these graphs as they can help questions get answered quickly and easily by the community.
Both the Modern and Crew graph can be constructed with the
TinekrFactory, which will construct an in-memory TinkerGraph with the data pre-loaded:
gremlin> graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph.traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.V() ==>v ==>v ==>v ==>v ==>v ==>v
Note the conventions in the above code. The
Graph instance is typically called “graph” and then to execute traversals (i.e. queries) one creates a
TraversalSource from that
Graph called “g”. Then, the query
g.V() executes a traversal that gets a list of all the vertices in “g”.
To create “The Crew” graph, which features meta/multi-properties, use
More information about using the toy graphs can be found in TinkerPop’s tutorial called The Gremlin Console.