Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Getting Started

Dan LaRocque edited this page · 79 revisions
This is the documentation for Titan 0.4.
Documentation for the latest Titan version is available at

In the beginning, there existed two deities known as Uranus and Gaia. They gave birth to the Titans (a race of powerful beings). Saturn, Titan of time, set reality in motion. Ultimately, time yielded the existence of the sky, the sea, and the end of life—death. To rule these notions, Saturn had three sons: Jupiter (sky), Neptune (sea), and Pluto (underworld). The son’s of Saturn were not Titans, but a race of seemingly less powerful deities known the world over as the Gods. Fearful that his sons would overthrow him, Saturn devoured them and imprisoned them in his stomach. This caused a great war between the Titans and Gods. Ultimately, the Gods won and Jupiter took the throne as leader of the Gods.




The Graph of the Gods

The examples in this section make extensive use of a toy graph distributed with Titan called The Graph of the Gods. This graph is diagrammed below. The abstract data model is known as a property graph and this particular instance describes the relationships between the beings and places of the Roman pantheon. Moreover, special text and symbol modifiers in the diagram (e.g. bold, underline, etc.) denote different schematics/typings in the graph.

  • key: a graph indexed key.
  • key *: a graph indexed key that must have a unique value.
  • key: a vertex-centric indexed key.
  • hollow head edge: a functional/unique edge (no duplicates).
  • tail crossed edge: a unidirectional edge (can only traverse in one direction).

Downloading Titan and Running the Gremlin Shell

Unbeknownst to the Gods, there still lived one Titan. This Titan can not be seen, has no name, and is only apparent in the fact that reality exists. Upon the shoulders of this lost Titan, all of reality hangs together in an undulating web of relations.

Titan can be downloaded from the Downloads section of the project repository (get the titan-all version). Once retrieved and unpacked, a Gremlin terminal can be started. The Gremlin REPL (i.e. interactive shell) is distributed with Titan and differs slightly from the main TinkerPop Gremlin distribution in that is comes preloaded with Titan-specific imports and helper methods. In the example below, is used, however, be sure to unzip the zip-file that was downloaded.

$ unzip
   creating: titan/
$ cd titan
$ bin/ 

         (o o)

The Gremlin terminal is a Groovy shell. Groovy is a superset of Java that has various shorthand notations that make interactive programming easier. Likewise Gremlin is a superset of Groovy with various shorthand notations that make graph traversals easy. The basic examples below demonstrate handling numbers, strings, and maps. The remainder of the tutorial will discuss graph-specific constructs.

gremlin> 100-10
gremlin> "Titan:" + " The Rise of Big Graph Data"
==>Titan: The Rise of Big Graph Data
gremlin> [name:'aurelius',vocation:['philosopher','emperor']]
==>vocation=[philosopher, emperor]

NOTE: Please refer to GremlinDocs for a easy to use Gremlin reference.

Loading Data Into Titan

The example below will load The Graph of the Gods dataset diagrammed above into Titan. When working with a fresh graph (beyond this tutorial), TitanFactory provides methods to create various Titan instances (e.g. local, distributed, etc.). A local, single machine instance of Titan is created using the directory) method. Other pages in the documentation demonstrate distributing Titan across multiple machines, for instance using Cassandra or using HBase. Refer to the storage backend overview on how to choose the optimal persistence mode. For the purpose of this tutorial, a pre-constructed local graph is provided that is loaded with the above Graph of the Gods diagram.

gremlin> g = GraphOfTheGodsFactory.create('/tmp/titan')           

The GraphOfTheGodsFactory.create() method does the following to the newly constructed graph prior to returning it:
  1. Creates a collection of global and vertex-centric indices on the graph.
  2. Adds all the vertices to the graph along with their properties.
  3. Adds all the edges to the graph along with their properties.

Please see the class source code:

For those using Titan/Cassandra (or Titan/HBase), be sure to make use of conf/ (or conf/ and GraphOfTheGodsFactory.load().

gremlin> g ='conf/')
gremlin> GraphOfTheGodsFactory.load(g)

Global Graph Indices

The typical pattern for accessing data in a graph database is to first locate the entry point into the graph using a graph index. That entry point is an element (or set of elements) — i.e. a vertex or edge. From the entry elements, a Gremlin path description describes how to traverse to other elements in the graph via the explicit graph structure.

Given that there is a unique index on name property, the Saturn vertex can be retrieved. The property map (i.e. the key/value pairs of Saturn) can then be examined. As demonstrated, the Saturn vertex has a name of “saturn,” an age of 10000, and a type of “titan.” The grandchild of Saturn can be retrieved with a traversal that expresses: “Who is Saturn’s grandchild?” (the inverse of “father” is “child”). The result is Hercules.

gremlin> saturn = g.V('name','saturn').next()

The property place is also in a graph index. The property place is an edge property. Therefore, Titan can index edges in a graph index. It is possible to query The Graph of the Gods for all events that have happened within 50 kilometers of Athens (latitude:37.97 and long:23.72). Then, given that information, which vertices were involved in those events.

gremlin> g.E.has('place',WITHIN,,23.72,50))
gremlin> g.E.has('place',WITHIN,,23.72,50)).collect { 
==>[hercules, hydra]
==>[hercules, nemean]

Graph indices are one type of index structure in Titan. Graph indices are accessible via the Graph.query() method. The second aspect of indexing in Titan is known as vertex-centric indices. Vertex-centric indices are accessible via the Vertex.query() method. Vertex-centric indices are described later.

Graph Traversal Examples

Hercules, son of Jupiter and Alcmene, bore super human strength. Hercules was a demigod because his father was a god and his mother was a human. Juno, wife of Jupiter, was furious with Jupiter’s infidelity. In revenge, she blinded Hercules with temporary insanity and caused him to kill his wife and children. To atone for the slaying, Hercules was ordered by the Oracle of Delphi to serve Eurystheus. Eurystheus appointed Hercules to 12 labors.


In the previous section, it was demonstrated that Saturns’ grandchild was Hercules. This can be expressed using a loop. In essence, Hercules is the vertex that is 2-steps away from Saturn along the in('father') path.

gremlin> hercules ='x').in('father').loop('x'){it.loops < 3}.next()

Hercules is a demigod. To prove that Hercules is half human and half god, his parent’s origins must be examined. It is possible to traverse from the Hercules vertex to his mother and father. Finally, it is possible to determine the type of each of them — yielding “god” and “human.”

gremlin> hercules.out('father','mother')
gremlin> hercules.out('father','mother').name
gremlin> hercules.out('father','mother').type
gremlin> hercules.type

The examples thus far have been with respect to the genetic lines of the various actors in the Roman pantheon. The property graph data model is expressive enough to represent multiple types of things and relationships. In this way, The Graph of the Gods also identifies Hercules’ various heroic exploits - his famous 12 labors. In the previous section, it was discovered that Hercules was involved in two battles near Athens. It is possible to explore these events by traversing battled edges out of the Hercules vertex.

gremlin> hercules.out('battled')
gremlin> hercules.out('battled').map
==>{name=nemean, type=monster}
==>{name=hydra, type=monster}
==>{name=cerberus, type=monster}
gremlin> hercules.outE('battled').has('time',,1)

The edge property time on battled edges is indexed by the vertex-centric indices of a vertex. Retrieving battled edges incident to Hercules according to a constraint/filter on time is faster than doing a linear scan of all edges and filtering (typically O(log n), where n is the number incident edges). Gremlin is intelligent enough to use vertex-centric indices when available. A toString() of a Gremlin expression shows the underlying query pipeline.

gremlin> hercules.outE('battled').has('time',,1)
==>[GremlinStartPipe, VertexQueryPipe(out,[battled],has,edge), IdentityPipe, InVertexPipe, PropertyPipe(name)]

More Complex Graph Traversal Examples

In the depths of Tartarus lives Pluto. His relationship with Hercules was strained by the fact that Hercules battled his pet, Cerberus. However, Hercules is his nephew — how should he make Hercules pay for his insolence?

The Gremlin traversals below provide more examples over The Graph of the Gods. The explanation of each traversal is provided in the prior line as a // comment.

Cohabiters of Tartarus

gremlin> pluto = g.V('name','pluto').next()
gremlin> // who are pluto's cohabitants?
gremlin> pluto.out('lives').in('lives').name                
gremlin> // pluto can't be his own cohabitant
gremlin> pluto.out('lives').in('lives').except([pluto]).name

Pluto’s Brothers

gremlin> // where do pluto's brothers live?
gremlin> pluto.out('brother').out('lives').name
gremlin> // which brother lives in which place?
gremlin> pluto.out('brother').as('god').out('lives').as('place').select
==>[god:v[16], place:v[8]]
==>[god:v[20], place:v[12]]
gremlin> // what is the name of the brother and the name of the place?
gremlin> pluto.out('brother').as('god').out('lives').as('place').select{}
==>[god:jupiter, place:sky]
==>[god:neptune, place:sea]

Finally, Pluto lives in Tartarus because he shows no concern for death. His brothers, on the other hand, chose their locations based upon their love for certain qualities of those locations.

gremlin> pluto.outE('lives').reason
==>no fear of death
gremlin> g.E.has('reason',CONTAINS,'loves')
gremlin> g.E.has('reason',CONTAINS,'loves').collect{
==>[jupiter, loves fresh breezes, sky]
==>[neptune, loves waves, sea]

Next Steps

This section presented some basic examples of how to traverse The Graph of the Gods in Titan. In essence, a graph database is all about representing some world (structure) and traversing it to solve problems (process).

The remainder of this documentation discusses more in-depth examples and configurations for using Titan. Specifically,

Something went wrong with that request. Please try again.