This tutorial describes how to set up JanusGraph to work with YugabyteDB and use the Gremlin console to load some data and run some graph commands.


To use JanusGraph with YugabyteDB, you need the following:

  • Install YugabyteDB and start a single node local cluster. Refer to Quick start.

  • JanusGraph. You can download from the JanusGraph downloads page. This tutorial uses v0.6.2.

    $ wget https://github.com/JanusGraph/janusgraph/releases/download/v0.6.2/janusgraph-0.6.2.zip
    $ unzip janusgraph-0.6.2.zip
    $ cd janusgraph-0.6.2/lib
  • Download cassandra-driver-core-3.8.0-yb-6.jar and copy it into janusgraph-0.6.2/lib.

    Rename the existing Cassandra driver:

    mv cassandra-driver-core-3.1.4.jar cassandra-driver-core-3.1.4.jar.orig

Run JanusGraph with YugabyteDB

Start the Gremlin console by running the following:

$ ./bin/gremlin.sh

You should see output similar to the following:

        (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

Use the YCQL configuration to initialize JanusGraph to talk to YugabyteDB.

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cql.properties')

Open the YugabyteDB Admin console to verify that the janusgraph keyspace and the necessary tables were created by navigating to http://localhost:7000/ (replace localhost with the IP address of any master node in a remote deployment). You should see the following:

List of keyspaces and tables when running JanusGraph on YugabyteDB

Load sample data

You can 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]

For reference, the following illustration shows the data loaded by the Graph of the Gods. For more information about the dataset, refer to Basic usage in the JanusGraph documentation.

Graph of the Gods


The following examples are derived from the examples in the JanusGraph documentation.

Graph traversal

Queries about Hercules

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')

Retrieve the Hercules vertex.

gremlin> hercules = g.V(saturn).repeat(__.in('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')

Complex graph traversal

Retrieve the Pluto vertex.

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')

Global graph index

Show all events that occurred in 50 kilometers of Athens (latitude:37.97 and long:23.72).

gremlin> g.E().has('place', geoWithin(Geoshape.circle(37.97, 23.72, 50)))

For events that occurred in 50 kilometers of Athens, show who battled whom.

gremlin> g.E().has('place', geoWithin(Geoshape.circle(37.97, 23.72, 50))).as('source').inV().as('god2').select('source').outV().as('god1').select('god1', 'god2').by('name')