Reputation: 1259
I have a Gremlin hierarchy of nodes which are referenced (Refer below pic). How can I retrieve all nodes, including their sibling nodes, at a specific provided level from root node ?
For instance,
How can I achieve this using Gremlin tinkerpop from root node ?
Upvotes: 0
Views: 78
Reputation: 41
You could use the repeat step in gremlin and go out the adjacent nodes until you match your desired level.
For the first case you can do something like this, without repeat, as you only need the adjacent nodes.
g.V('root_node').out().toList()
For the rest of the use cases you can use the repeat like so:
g.V('root_node').repeat(out()).times(2).path() # For level 2
and
g.V('root_node').repeat(out()).times(3).path() # For level 3
Lastly, here's the docs for the repeat()
step https://tinkerpop.apache.org/docs/current/reference/#repeat-step
Note: the queries are not tested on a gremlin server but you should be able to tweak them for your use case/
Upvotes: 2