Skip to main content
Version: Graph 2.2.0

Basic Usage


There are several options for connecting to and interacting with Aerospike Graph Service (AGS), such as:

  • The Gremlin Console, an interactive command-line terminal for sending queries and receiving responses.

  • A client application. This page provides code samples for Python and Java client code.

  • A Jupyter Notebook.

Working with graph data

You can use a client application or the Gremlin Console to query an existing data set, or add new edges and vertices to a data set. The examples below demonstrate adding new vertices one at a time to a database. To bulk load new data into a Graph database, use the Graph bulk loader.

Binding to Docker

Kelvin Lawrence has compiled and made public a data set designed for use with a graph database . It contains information about airlines, airports around the world, and routes between them. The data set is large enough to be interesting and useful, but small enough to be practical for testing and experimentation purposes.

  1. Download one of the .graphml data files here.

  2. When you start the AGS Docker image, use the -v option to bind the local .graphml file directory to a directory in the Docker container.

    For example, if you download the data file air-routes-small.graphml to the directory /home/users/data, start the AGS Docker image with the -v option:

    docker run -p 8182:8182 \
    -e aerospike.client.namespace="test" \
    -e"aerospike-devel-cluster-host1:3000,aerospike-devel-cluster-host2:3000" \
    -v /home/user/data/:/opt/air-routes/ \
  3. Use the Gremlin console to load the air-routes data set into Aerospike Graph with the following command:

    g.with("evaluationTimeout", 24L * 60L * 60L * 1000L).io("/opt/air-routes/air-routes-small.graphml").with(IO.reader, IO.graphml).read()

    The air-routes data set may take a few minutes to load, depending on your host hardware and network configuration.


  1. Download the latest version of the Gremlin Console from the Apache website.


    You must have a Java runtime to use the Gremlin console.

  2. After unzipping the package and navigating to the application folder, start the console with the following command:

  1. Connect via the Aerospike Graph Service (AGS) Docker image. See the instructions if you haven't yet started an AGS Docker image.

    g = traversal().withRemote(DriverRemoteConnection.using("GREMLIN_SERVER_IP_ADDRESS", 8182, "g"));

    Replace GREMLIN_SERVER_IP_ADDRESS with the accessible IP address of your AGS Docker image.

    Expected output:

    graphtraversalsource[emptygraph[empty], standard]
  1. Add a new vertex with the addV function:


    Expected output:

  1. Return the ID of your newly-created vertex:


    Expected output:


Sample Gremlin queries with the air-routes data set

  1. Find the airport with code "DFW":

  2. Find the number of airports in this graph:

  3. Find the number of flights going out of the airport with code "SFO":

  4. Get all the cities with flights that are > 4000 miles:

  5. Find all the airports in the USA you can fly to from London Heathrow (LHR):

  6. Find all the unique locations in the world and in the US that I can get to from SFO through a 2 hop flight:

    g.V().has("code", "SFO").out().out().dedup().fold().project("totalAirportCountFromSFO",    "USAirportCountFromSFO").by(__.unfold().count()).by(__.unfold().has("country", "US").count())

To get performance metrics for a query, append .profile() to the end of the command.

Additional resources