Search code examples
propertiesneo4jtraversal

Neo4j Traversal not load all properties


During my Traversal, I look at one property. But it seems that all properties are loaded, which makes the Traversal slower. Is there are way to configure a lazy load for properties I don't want to look at?

TraversalDescription td = Traversal.description().evaluator( Evaluators.atDepth(1) );
for ( Path p : td.traverse( myNode ) ) {
    String nodeName = (String) p.endNode().getProperty("name");
    // do some stuff
}

I only found a clue here...

Thanks!

===

Edit : My goal is to sort the nodes by names, for example movies...


Solution

  • Upon first access of any property of a node or relationship all properties are loaded into memory, see http://docs.neo4j.org/chunked/stable/performance-guide.html#_neo4j_primitives_lifecycle.

    Best practice for high performant traversals is to change your graph model in a way that the traversal does not have to touch properties while traversing. Depending on your domain you can get to that by e.g. using more verbose relationship types or by the usage of labels in Neo4j 2.0.

    You're code snippets uses the deprecated traversals, you should migrate your code to use the Traversal API as documented at http://docs.neo4j.org/chunked/stable/tutorial-traversal-java-api.html.