1
votes

I am trying to get all the incoming and outgoing nodes for a specific node in Neo4j using the traverser. My code looks like this:

    ArrayList<Node> outputList = new ArrayList<>();

    for (Node connectedNode: nodeTraversal.relationships()
                                          .evaluator(Evaluators.toDepth(1))
                                          .traverse(this.inputNode)
                                          .nodes()) {
        outputList.add(connectedNode) ;
    }

the relationships() functions needs a relationship name as an argument but I would like to get all outgoing nodes regardless of the relationships the node is connected to. What is the most time efficient way to achieve this ?

1

1 Answers

1
votes

Not being 100% sure here, but I think if you just omit relationships() it will implicitly traverse all relationship types in any direction.

In case this does not work, use

nodeTraversal.expand(PathExpanders.allTypesAndDirections())
.evaluator(.....)....

That one will work for sure.