Neo4j is drawing two relationships using APOC shortest path query based on relationship value, however it should be one

Viewed 32

Im still new to Neo4j, Im trying to figure out how to get Neo4j to return and draw only the shortest path between two nodes. im currently using APOC procedure.

basically i have two nodes (Site-1 & Site-2) with two relationships between them (relationship-1 (Link, distance:10) & (relationship-1 (Link, distance:40).

result screen shot is in the attachment

I used the below APOC procedure

CALL apoc.algo.dijkstra(site1, site2, 'Link', 'distance') YIELD path, weight
Return path, weight ```

the graph returned with a drawing of two relationship between the two nodes, however it should only draw one. any idea on how i can return one only?
1 Answers

Neo4j browser is a tool, that makes cypher querying easier and also helps in visualizing the graph as well. What you are seeing is not an error exactly. Neo4j browser is configured by default, to show all the relationships of a node when expanded. It doesn't necessarily represent your query output. I replicated your case on my system, I also received the same graph.

enter image description here

But the actual query response is under the Table tab.

enter image description here

This is the whole response that I got:

[
  {
    "path": {
      "start": {
        "identity": 5,
        "labels": [
          "Site1"
        ],
        "properties": {}
      },
      "end": {
        "identity": 6,
        "labels": [
          "Site2"
        ],
        "properties": {}
      },
      "segments": [
        {
          "start": {
            "identity": 5,
            "labels": [
              "Site1"
            ],
            "properties": {}
          },
          "relationship": {
            "identity": 0,
            "start": 5,
            "end": 6,
            "type": "LINK",
            "properties": {
              "distance": 10
            }
          },
          "end": {
            "identity": 6,
            "labels": [
              "Site2"
            ],
            "properties": {}
          }
        }
      ],
      "length": 1.0
    },
    "weight": 10.0
  }
]

As you can see, only one path and weight are returned. This is what your query outputs and this is what your language driver will receive be it Javascript, java, anything.

Related