Reputation: 127
below Shortestpath query returns many paths instead of one path.
MATCH PATHS=shortestPath((a:Endpoint{ nodeName: 'BRS-PE-SR7-X03B' }) -[*]-(b:Endpoint{ nodeName: 'LDN-PE-SR7-X03C' }) RETURN PATHS
Can anybody explain how iternally it calculates the paths and return the shortest path for the below scenarios.
My understanding is it should return ONLY one path.Am I right?
Upvotes: 0
Views: 168
Reputation: 491
The shortest path algorithm as provided by the REST API provides ALL SHORTEST PATHS between two nodes. This implies that if the minimum number of hops are same in more than one path, then you will get all of those shortest paths.
(https://neo4j.com/docs/rest-docs/current/#rest-api-find-all-shortest-paths).
Upvotes: 1
Reputation: 66999
The SHORTESTPATH
function finds the single shortest path between two specific nodes.
If multiple Endpoint
nodes can have the same nodeName
value, this can explain why you are getting multiple shortest paths.
If this is the reason for your results, at least one of the 2 counts returned by this query should exceed 1:
MATCH
(a:Endpoint{ nodeName: 'BRS-PE-SR7-X03B' }),
(b:Endpoint{ nodeName: 'LDN-PE-SR7-X03C' })
RETURN COUNT(DISTINCT a), COUNT(DISTINCT b);
Upvotes: 1