Skip to content

Gremlin queries

Next, use the Gremlin Console to experiment with Gremlin queries in AGS. Explore vertices, traverse edges, and gain hands-on experience with basic graph traversal patterns to better understand the data model.

Query the air-routes data

  1. Add a vertex with the addV function:

    Terminal window
    g.addV('foo').property('company','aerospike').property('scale','unlimited')
    Example response
    v[-6001]
  2. Return the ID of the newly-created vertex:

    Terminal window
    g.V().has('company','aerospike')
    Example response
    v[-6001]
  3. Find the airport with code “DFW”:

    Terminal window
    g.V().has('code','DFW')
    Example response
    v[8]
  4. Find the number of airports in this graph:

    Terminal window
    g.V().hasLabel('airport').count()
    Example response
    3504
  5. Find the number of flights going out of the airport with code “SFO”:

    Terminal window
    g.V().has('code','SFO').outE().count()
    Example response
    157
  6. Get all the cities with flights that are > 4000 miles:

    Terminal window
    g.E().has("dist", P.gt(4000L)).inV().values("city").dedup()
    Example response
    Fortaleza
    Cayo Largo del Sur
    Varadero
    Holguin
    Puerto Plata
  7. Find all the airports in the USA that have flights from London Heathrow (LHR):

    Terminal window
    g.V().has('code','LHR').out('route').has('country','US').values('code')
    Example response
    ATL
    MSY
    EWR
    DTW
    JFK
    SAN
  8. Find all the unique locations outside and inside the US that are accessible from SFO through a 2 hop flight:

    Terminal window
    g.V().has("code", "SFO").out().out().dedup().fold().project("totalAirportCountFromSFO", "USAirportCountFromSFO").by(__.unfold().count()).by(__.unfold().has("country", "US").count())
    Example response
    [totalAirportCountFromSFO:1904,USAirportCountFromSFO:455]
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?