Neo4j - shortestPath not returning path length

1.2k Views Asked by At

I am attempting to execute a "shortestPath" cypher query in Neo4j but am encountering a strange difficulty. I should get "2 nodes" as the shortest path, however I get nothing.

MATCH p=shortestPath((charlize:Person)-[:KNOWS]-(bacon:Person)) 
WHERE charlize.name="Charlize Theron" AND bacon.name="Kevin Bacon" 
RETURN length(p); 

I do believe I'm running the latest version of Neo4j. Could this be an issue?

Regards!

1

There are 1 best solutions below

0
On BEST ANSWER

The problem is you haven't specified a variable-length path. [:KNOWS] means that you are looking for a pattern where there is a single :KNOWS relationships between the two nodes, and there isn't one.

You want to use [:KNOWS*] here. Here's the documentation for variable length path matching for reference.