Skip to main content
Loading
Version: Graph 2.2.0

Basic Usage

Overview

This page describes 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 to add edges and vertices to a data set. The examples below demonstrate adding vertices one at a time to a database. To bulk load data into a Graph database, use the 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.client.host="aerospike-devel-cluster-host1:3000,aerospike-devel-cluster-host2:3000" \
    -v /home/user/data/:/opt/air-routes/ \
    aerospike/aerospike-graph-service
  3. Use the Gremlin console to load the air-routes data set into AGS 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()
    note

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

Examples

note

To use the Gremlin console, you must have a Java runtime.

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

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

    ./bin/gremlin.sh
  3. Connect using the 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 vertex with the addV function:

    g.addV('foo').property('company','aerospike').property('scale','unlimited')

    Expected output:

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

    g.V().has('company','aerospike')

    Expected output:

    v[-1]

    Sample Gremlin queries with the air-routes data set

  2. Find the airport with code "DFW":

    g.V().has('code','DFW')
  3. Find the number of airports in this graph:

    g.V().hasLabel('airport').count()
  4. Find the number of flights going out of the airport with code "SFO":

     g.V().has('code','SFO').outE().count()
  5. Get all the cities with flights that are > 4000 miles:

    g.E().has("dist", P.gt(4000L)).inV().values("city").dedup()
  6. Find all the airports in the USA you can fly to from London Heathrow (LHR):

    g.V().has('code','LHR').out('route').has('country','US').values('code') 
  7. 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