Joel Stevick
Joel Stevick

Reputation: 2028

Gremlin: how to get all of the graph structure surrounding a single vertex into a subgraph

I would like to get all of the graph structure surrounding a single vertex into a subgraph.

The TinkerPop documentation shows how to do this for a fixed number of traversal steps.

My question: are there any recipes for getting the entire surrounding structure (which may include cycles) without knowing ahead of time how many traversal steps are needed?


I have updated this question for the benefit of anyone who might land on this question, here is a gremlin statement that will capture an arbitrary graph structure that surrounds a vertex with id='xxx'

g.V('xxx').repeat(out().simplePath()).until(outE().count().is(eq(0))).path()

-- this incorporates Stephen Mallete's suggestion to use simplePath within the repeat step.

Upvotes: 0

Views: 434

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

That example uses repeat()...times() but you could easily replace times() with until() and not know the number of steps ahead of time. See more information in the Reference Documentation on how repeat() works to see how to express different types of flow control and traversal stop conditions.

Upvotes: 1

Related Questions