Using the air-routes data set, the following Gremlin query will find five routes between Austin (AUS) and Wellington (WLG).
g.V().has('code','AUS').
repeat(out('route').simplePath()).
until(has('code','WLG')).
limit(5).
path().
by('code')
which returns the paths (routes) with each airport code displayed:
1 path[AUS, DFW, SYD, WLG]
2 path[AUS, IAH, SYD, WLG]
3 path[AUS, IAH, AKL, WLG]
4 path[AUS, LAX, SYD, WLG]
5 path[AUS, LAX, MEL, WLG]
In openCypher a similar query can be written, along the lines of
MATCH p=(a:airport {code: 'AUS'})-[:route*]->(w:airport {code: 'WLG'})
RETURN p
LIMIT 5
But this returns all of the properties for the entire path (nodes and edges). Is there a simple way to get a result back that resembles the output from the Gremlin query?
The queries were run using Amazon Neptune which allows Gremlin and openCypher queries over the same data, and using the graph-notebook notebooks.
The openCypher query can be modified to use "list comprehension" as follows
which returns
These work in a similar way to list comprehension in Python. For each node, in each path, the variable
aptis assigned. From there we can just extract the airport code usingapt.code.