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
addVfunction:g.addV('foo').property('company','aerospike').property('scale','unlimited')Example response v[-6001] -
Return the ID of the newly-created vertex:
g.V().has('company','aerospike')Example response v[-6001] -
Find the airport with code “DFW”:
g.V().has('code','DFW')Example response v[8] -
Find the number of airports in this graph:
g.V().hasLabel('airport').count()Example response 3504 -
Find the number of flights going out of the airport with code “SFO”:
g.V().has('code','SFO').outE().count()Example response 157 -
Get all the cities with flights that are > 4000 miles:
g.E().has("dist", P.gt(4000L)).inV().values("city").dedup()Example response FortalezaCayo Largo del SurVaraderoHolguinPuerto Plata -
Find all the airports in the US that have flights from London Heathrow (LHR):
g.V().has('country','US').where(in('route').has('code','LHR')).values('code').toList()Example response IAHCHSORDEWRBWIPIT -
Find all the unique locations outside and inside the US that are accessible 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())Example response [totalAirportCountFromSFO:1904,USAirportCountFromSFO:455]