I have a graph with the following vertices and edges for example:
A->B->C
and I want to write a gremlin query that will return a path like A->C so it will be visualized in the Jupyter notebook I'm using (aws-notebooks-visualization.
This means returning a fictive edge from A to C although it doesn't really exist in the original graph.
Is it possible?
This is a case where flatMap
can help. Given this graph:
g.addV('A').as('a').
addV('B').as('b').
addV('C').as('c').
addE('link').from('a').to('b').
addE('link').from('b').to('c')
The following query will generate the result you are looking for:
g.V().hasLabel('A').
flatMap(out().out()).
path().
by(elementMap())