0

I have created a graph named 'family tree' and have added three persons with the label Persons. enter image description here

Now i'm adding an edge between Andrew James and Timathy James such that, Andrew is the son of Timathy using the following command:

enter image description here

Now when I display the edges I get: enter image description here

I am getting that Andrew is the son of Timathy, and also the opposite. What am I doing wrong here.

PS: Let's ignore the year_born and year_died for now.

  • Sorry, we [can't accept images of code, data or errors](https://meta.stackoverflow.com/a/285557). Post those as *text*, so that we can try to reproduce the problem without having to re-type everything, and your question can be properly indexed or read by screen readers. – Martijn Pieters Mar 16 '23 at 10:08

3 Answers3

1

In your last query, you are missing the >. It should be:

MATCH (a:Person)-[e:Son_of]->(b:Person)
1

MATCH (a)-[e]-(b) checks for incoming or outgoing edges for each vertex in given pattern.

Suppose there is a pattern created like (a)-[e]->(b). Now the way MATCH (a)-[e]-(b) works is, it will see for vertex 'a', if there is any edge 'e' outgoing or incoming towards it from 'b'. Now it will see for vertex 'b', if there is any edge 'e' outgoing or incoming towards it from 'a'.

In this case, 'a' has an outgoing edge 'e' towards 'b', and 'b' has incoming edge 'e' from 'a'. Hence output is kind of duplicated with just vertices opposite. If you display the start and end id of edge, you will notice that it is same for both results, just the vertices are opposite in output.

Adding > to your MATCH query (as answered above by rafsun) should resolve your question.

0

So actually what is happening in this query is that you are creating an edge and not a directed edge, which is why it is giving you this result.

Add -> for the directed edge in the above query and rerun it. It will surely workAdd -> here

Now when you add '->' at the red circled thing it will indicate that a is the son of b.

Talha Munir
  • 121
  • 5