I'm fairly new to Gremlin and I'm trying to make a query more efficient.
With a graph that looks something like this:
[vertex: label=a] -> [vertex: label=b] -> [vertex: label=c] -> [vertex: label=d]
I need to traverse the graph, and get the results for each step of the traversal.
For example, from my base Vertex I may need to get everything related to it with the label "b" and everything related to "b" with the label "c" and so on.
I can do the requests individually like this:
results1 = g.V('someid').out().hasLabel('b').toList()
results2 = g.V('someid').out().hasLabel('b').out().hasLabel('c').toList()
results3 = g.V('someid').out().hasLabel('b').out().hasLabel('c').out().hasLabel('d').toList()
but that seems counter intuitive, and the response time starts to stack up.
I'm not really sure what I'm looking for, but maybe someway to continue searching a subset of the graph rather than starting from the base vertex every time.
EDIT:
I found the Union step, but this seems to combine multiple small queries into one big query and I believe ends up with the same inefficiencies as doing all the queries individually.
V()
step as one option. – Kelvin Lawrence