Search code examples
gremlingraph-traversaltinkerpop3

Gremlin Match Traversal that contains a repetitive structure


Hi I am trying to match a subgraph that may have a path of Extends edges.

enter image description here

The known parts are the Vertices with ids 1,2,3 and 6 and their edges.. What is not known is the number of vertices and their ids between 1 and 6. Match starts from vertex with id=1. The match traversal needs to match the whole subgraph with a limit of let's say 10 steps between 4 and 6. In the trivial case vertex with id 6 is directly connected with vertex having id = 1 through edge ContainsB.

Any help is appreciated!


Solution

  • I think this seems to work the way I wanted:

    g.V().match(
       __.as("s").hasId("1").outE("ContainsB").inV().until(hasId("6")).repeat(out("Extends")).limit(10),
       __.as("s").hasId("1").outE("ContainsA").inV().hasId("2"),
       __.as("s").hasId("1").outE("ContainsC").inV().hasId("3")
    )