-1

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?
Charchit Kapoor
  • 8,934
  • 2
  • 8
  • 24
Moaz
  • 19
  • 4
  • Pls give us sample data so qe ca simulate it. Thanks – jose_bacoy Sep 17 '22 at 23:05
  • It works on my system, can you share the statements, using which you created your graph? – Charchit Kapoor Sep 18 '22 at 09:50
  • Hello guys, i have attached the screenshot for the graph output, as you can see the graph is returning two links, however it should only return one link, if you look at the right hand you will see that in the Overview the returned values are 2 nodes and 1 link. – Moaz Sep 18 '22 at 17:30
  • It's not an error. Neo4j browser will show you all the relationships of a node. Goto, to the table section, there you will see only one path is returned. – Charchit Kapoor Sep 19 '22 at 05:16
  • So, there is no way to make Neo4j to just draw the targeted relationship, in case i used a javascript to get the graph from neo4j, will i also get both links or only one? – Moaz Sep 19 '22 at 07:14
  • Added an answer – Charchit Kapoor Sep 19 '22 at 08:58

1 Answers1

1

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.

Charchit Kapoor
  • 8,934
  • 2
  • 8
  • 24