Unable to create undirected graph

Hi,
There are some confusion about create an undirected graph in Neo4j. The Neo4j Graph Algorithm book suggests that the undirected relation can be created. I am currently working on an undirected social network in Neo4j. Nodes are represent a person and the link between them is undirected which means they both know each other (eg. A-B; A knows B and B knows A).

I was panning to generate a graph with links (without arrow pointed) like this:
image
However, from the small example I proposed, the output I got was this:
image
Following is the query I used to generate an undirected relation graph.

LOAD CSV WITH HEADERS FROM 'file:///RelationTest.csv'AS line
MATCH (source:Person {id:line.id1}),(target:Person{id:line.id2})
MERGE (source)-[:linksTo]-(target)

I am confused that the results of MERGE (source)-[:linksTo]-(target) and MERGE (source)-[:linksTo]->(target) are the same.
Why are the same results happened? So how can I generate a undirected graph?

I am new to Neo4j could anyone help me to clarify this confusion?

Neo4j graphs are always directed, relationships always have a direction. The difference is whether you care about that direction or not in your queries.

A MERGE lacking a direction as in your example, MERGE (source)-[:linksTo]-(target), means you don't care about what direction you're matching to this, so it will MATCH to any existing pattern regardless of which way the relationship is directed. And if no such pattern exists, it will be created with an arbitrary direction (likely left to right, but the point is that by omitting the direction, you don't care).

Likewise, if you want to MATCH a pattern and the direction doesn't matter, then leave the direction out of the pattern.

1 Like

Okay, thank you Andrew!