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,
- If I provide level 1 as input, I want Eq1, Eq2, Eq3, and Eq5 as an output.
- If I provide level 2 as input, I want Eq1, Eq2, Eq3, Eq4, and Eq5 as an output
- If I provide level 3 as input, I want Eq1, Eq2, Eq3, Eq4, Eq4.1, and Eq5 as an output.
Note: Output nodes can be in any sequence.
How can I achieve this using Gremlin tinkerpop from root node ?
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.
For the rest of the use cases you can use the repeat like so:
and
Lastly, here's the docs for the
repeat()
step https://tinkerpop.apache.org/docs/current/reference/#repeat-stepNote: the queries are not tested on a gremlin server but you should be able to tweak them for your use case/