Neo4j Using a custom evaluator to get the depth a node was retrieved at

I'm using the latest version of Neo4j to build up a graph of nodes and relationships with the Java API.

My problem is that I need to traverse the nodes to a certain depth. There may exist a relationship between two nodes at the same depth in the database, but I don't want to return that relationship in the traversal.

I tried to make a custom Evaluator by implementing the Evaluator interface but the only method it overrides is Evaluation evaluate(Path path) . It doesn't appear to have the notion of depth associated with it.

I would really appreciate some advice on how to either associate a node with its depth (when traversing from a particular node) or prune a relationship where two nodes are in the same level.


You can use Evaluators.atDepth() to get a predefined Evaluator that only includes paths with a certain depth.

In your custom evaluator you can simply check the length of the passed path parameter to decide if you want to include this path or not e.g. with:

Evaluation evaluate(Path path) {
    return path.length() == 4 ? Evaluation.INCLUDE_AND_PRUNE : Evaluation.EXCLUDE_AND_CONTINUE);

Have you tried Cypher for that, something like

start n = node(1) match p=n-[*4]->(x) return x, length(p) 


The path has a length(), which is the depth. The length is equal to the number of relationships in the path, i.e. number of nodes - 1.

Need Your Help

MacVim caught deadly signal

text-editor macvim

When I start MacVim within terminal I get a nasty error message saying it has caught a deadly singal SEGV. I really don't know what's going on. Like wise when I start the application by double clic...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.