cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Relationship between nodes.

vence_andersen1
Graph Buddy

I have a data like below

vence_andersen1_1-1662371548115.png

Here I am trying to merge all values of Alpha with all values of Beta. Example I want a relationship between a-z, a-y, a-x, a-w, a-v then b-z, b-y, b-x, b-w, b-v and so for the rest. 

Can I achieve this using the queries? Thanks in advance.

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

One approach would be to collect both columns into lists and use a double unwind to get the Cartesian product of the two lists. This would allow you to relate each pair of elements from both lists. 

Something like this: 

load csv with headers from “file:///Data.csv” as line

with collect(line.Alpha) as alpha, collect(line.Beta) as beta

unwind alpha as a

merge(n:NodeType{id: a})

unwind beta as b

merge(m:NodeType{id: b})

merge(n)-[:HAS_REL]->(m)

 

 

View solution in original post

1 REPLY 1

glilienfield
Ninja
Ninja

One approach would be to collect both columns into lists and use a double unwind to get the Cartesian product of the two lists. This would allow you to relate each pair of elements from both lists. 

Something like this: 

load csv with headers from “file:///Data.csv” as line

with collect(line.Alpha) as alpha, collect(line.Beta) as beta

unwind alpha as a

merge(n:NodeType{id: a})

unwind beta as b

merge(m:NodeType{id: b})

merge(n)-[:HAS_REL]->(m)

 

 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.