Search code examples
neo4jspring-data-neo4j-4neo4j-ogm

Shortestpath query returns many paths instead of one path


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?


Solution

  • 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);