In this tutorial, we are first going to setup JanusGraph to work with YugaByte DB as the underlying database. Then, using the Gremlin console, we are going to load some data and run some graph commands.

1. Start Local Cluster

Start a cluster on your local machine. Check that you are able to connect to YugaByte DB using cqlsh by doing the following.

$ cqlsh
Connected to local cluster at
[cqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.

system_schema  system_auth  system


2. Download JanusGraph

Download from the JanusGraph downloads page. This tutorial uses the 0.2.0 version of JanusGraph.

cd janusgraph-0.2.0-hadoop2

3. Run JanusGraph with YugaByte DB

  • Start the Gremlin console by running ./bin/ You should see something like the following.
$ ./bin/
         (o o)
plugin activated: janusgraph.imports
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.hadoop
plugin activated: tinkerpop.spark
plugin activated: tinkerpop.tinkergraph
  • Now use the CQL config to initialize JanusGraph to talk to YugaByte.
gremlin> graph ='conf/')
  • Open the YugaByte DB UI to verify that the janusgraph keyspace and the necessary tables were created by opening the following URL in a web browser: http://localhost:7000/ (replace localhost with the ip address of any master node in a remote depoyment). You should see the following.

List of keyspaces and tables when running JanusGraph on YugaByte DB

4. Load Sample Data

We are going to load the sample data that JanusGraph ships with - the Graph of the Gods. You can do this by running the following:

gremlin> GraphOfTheGodsFactory.loadWithoutMixedIndex(graph,true)
gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[cql:[]], standard]

5. Graph Traversal Examples

For reference, here is the graph data loaded by the Graph of the Gods. You can find a lot more useful information about this in the JanusGraph getting started page.

Graph of the Gods

  • Retrieve the Saturn vertex
gremlin> saturn = g.V().has('name', 'saturn').next()
  • Who is Saturn’s grandchild?
gremlin> g.V(saturn).in('father').in('father').values('name')
  • Queries about Hercules
gremlin> hercules = g.V(saturn).repeat('father')).times(2).next()

// Who were the parents of Hercules?
gremlin> g.V(hercules).out('father', 'mother').values('name')

// Were the parents of Hercules gods or humans?
gremlin> g.V(hercules).out('father', 'mother').label()

// Who did Hercules battle?
gremlin> g.V(hercules).out('battled').valueMap()

// Who did Hercules battle after time 1?
gremlin> g.V(hercules).outE('battled').has('time', gt(1)).inV().values('name')

6. Complex Graph Traversal Examples

  • Who are Pluto’s cohabitants?
gremlin> pluto = g.V().has('name', 'pluto').next()

// who are pluto's cohabitants?
gremlin> g.V(pluto).out('lives').in('lives').values('name')

// pluto can't be his own cohabitant
gremlin> g.V(pluto).out('lives').in('lives').where(is(neq(pluto))).values('name')
gremlin> g.V(pluto).as('x').out('lives').in('lives').where(neq('x')).values('name')
  • Queries about Pluto’s Brothers.
// where do pluto's brothers live?
gremlin> g.V(pluto).out('brother').out('lives').values('name')

// which brother lives in which place?
gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select('god', 'place')

// what is the name of the brother and the name of the place?
gremlin> g.V(pluto).out('brother').as('god').out('lives').as('place').select('god', 'place').by('name')

7. Global Graph Index Examples

NOTE: Secondary indexes in YugaByte DB are coming soon. These queries will iterate over all vertices to find the result.

  • Geo-spatial indexes - events that have happened within 50 kilometers of Athens (latitude:37.97 and long:23.72).
// Show all events that happened within 50 kilometers of Athens (latitude:37.97 and long:23.72).
gremlin> g.E().has('place', geoWithin(, 23.72, 50)))

// For these events that happened within 50 kilometers of Athens, show who battled whom.
gremlin> g.E().has('place', geoWithin(, 23.72, 50))).as('source').inV().as('god2').select('source').outV().as('god1').select('god1', 'god2').by('name')