Skip to main content
Loading
Version: Graph 2.0.0

Basic Usage

Overview

There are several options for connecting to and interacting with Aerospike Graph. Some possibilities are:

  • 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.

Kelvin Lawrence has compiled and made public a data set containing information about airlines, airports around the world, and routes between them, designed for use with a graph database. The data set is large enough to be interesting and useful, but small enough to be practical for testing and experimentation purposes. To run the following examples, download one of the .graphml data files here.

To use the .graphml file, you must bind it to a Docker volume. 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

You can 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()
note

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

Supported data types

For the vertex ~id field, AGS supports the following data types:

  • Long
  • Integer
  • Double
  • String

For vertex and edge property fields, AGS supports the following data types:

  • String
  • List
  • Integer
  • Long
  • Double
  • Float
  • Boolean

Examples

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

    note

    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:

    ./bin/gremlin.sh
  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:

    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

  1. Find the airport with code "DFW":

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

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

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

    g.E().has("dist", P.gt(4000L)).inV().values("city").dedup()
  5. 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') 
  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