## Breadth-First Traversal Fact Check

Using the Neptune Query Profiling, I have found out that Gremlin queries seems to use depth first strategy to search things and as a result it tends to be both time and resource intensive especially when what I am looking for is a node just a 1 or 2 levels below. To do a Breadth-First Traversal the following approach has been suggested, but not sure if this really does the trick. If my goal is to find nearest nodes quickly, what could be efficient approaches?
g.V().has('label', 'startingLabel') // Start at your initial vertices
.repeat(
out().simplePath() // Explore outward, avoid cycles
).until(
has('label', 'targetLabel') // Stop if you reach the target
).emit() // Emit all the vertices found at each level
g.V().has('label', 'startingLabel') // Start at your initial vertices
.repeat(
out().simplePath() // Explore outward, avoid cycles
).until(
has('label', 'targetLabel') // Stop if you reach the target
).emit() // Emit all the vertices found at each level
Solution:
Neptune uses BFS as the default traversal strategy. You can change the method in which a repeat() is executed via the query hint as noted here: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-query-hints-repeatMode.html
Gremlin repeatMode query hint - Amazon Neptune
The Neptune repeatMode query hint specifies how the Neptune engine evaluates the repeat() step in a Gremlin traversal: breadth first, depth first, or chunked depth first.
Jump to solution
1 Reply
Solution
triggan
triggan2mo ago
Neptune uses BFS as the default traversal strategy. You can change the method in which a repeat() is executed via the query hint as noted here: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-query-hints-repeatMode.html
Gremlin repeatMode query hint - Amazon Neptune
The Neptune repeatMode query hint specifies how the Neptune engine evaluates the repeat() step in a Gremlin traversal: breadth first, depth first, or chunked depth first.
Want results from more Discord servers?
Add your server