简体   繁体   中英

Travers through Neo4j nodes and relationships in JAVA using REST API

I want to traverse through Neo4j database nodes and relationships in java (not the embedded one. I want to use REST API). I have following method.

public void testTraverse(Node startNode) {
        for (Path position : Traversal.description()
                .depthFirst()
                .uniqueness(Uniqueness.NODE_GLOBAL)
                .evaluator(Evaluators.toDepth(10)).traverse(startNode)) 
        {
            System.out.println(position.lastRelationship().toString()+"\n--------------------------------\n");
        }
        for(Node node:Traversal.description().traverse(startNode).nodes()) {
            System.out.println(node.getProperty("name"));
        }
}

When calling this method, how I can create that startNode of type Node, which I want to pass as the parameter?

I am very new to Neo4j. Please help me. Alternative methods for Neo4j-Java-ReST is also warm welcomed...

Well, that starting node would have to be a node that you previously stored somehow.

Via the GraphDatabaseService instance, you could look up a node either by its ID:

Node yourNode = graphDatabaseService.getNodeById(0L);

...or through an index:

Node yourNode = graphDatabaseService.forNodes("anIndexName").get("id", 42).getSingle();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM