0

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?

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Avner Levy
  • 6,601
  • 9
  • 53
  • 92

1 Answers1

1

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())

enter image description here

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38