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
-
Add a vertex with the
addV
function:Terminal window g.addV('foo').property('company','aerospike').property('scale','unlimited')Example response v[-6001] -
Return the ID of the newly-created vertex:
Terminal window g.V().has('company','aerospike')Example response v[-6001] -
Find the airport with code “DFW”:
Terminal window g.V().has('code','DFW')Example response v[8] -
Find the number of airports in this graph:
Terminal window g.V().hasLabel('airport').count()Example response 3504 -
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 -
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 FortalezaCayo Largo del SurVaraderoHolguinPuerto Plata -
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 ATLMSYEWRDTWJFKSAN -
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]