Struggling to Draw Relationship from index i of List1 to index i of List2

Hi :slight_smile:
I've been struggling for awhile trying to upload transactions to Neo4j. I have 1 list of "from" addresses, another list of "to" addresses, and a third list of "values". I want to draw a single relationship from an index in the "from" list to the corresponding index in the "to" list, each including the corresponding index of the "values" list. E.g.:

(a:user {id: from_address})-[:SENT {value: value}]->(b:user {id: to_address})

My preliminary solution was to try unwinds and foreach's but each item from my first list sends to every single index of list 2 creating wayyy too many incorrect relationships. My sample code is below:

unwind [A1, B2, C3] as val
unwind ['a','b','c'] as from_addr
merge (a:utest {id: from_addr}) with a
unwind ['1','2','3'] as to_addr
merge (b:utest {id: to_addr}) with distinct a, b
Create (a)-[:SENT {val} ]->(b)

I feel I'm very close and am just wondering how I can have 6 nodes with only 3 relationships (a to 1, b to 2, c to 3. Thanks!!

@andrew.bowman Just wanted to ping here to clarify the details of my question re: the other chained-unwinds post :)

Hello,

Why don't you build a list of dict instead of 3 lists, like this you could unwind one time and get everything at the same time:)

Something like : [{val: 'A1', from_addr: 'a', to_addr; '1'}, {val: 'B2', from_addr: 'b', to_addr; '2'}, {val: 'C3', from_addr: 'c', to_addr; '3'}]

UNWIND [{val: 'A1', from_addr: 'a', to_addr; '1'}, {val: 'B2', from_addr: 'b', to_addr; '2'}, {val: 'C3', from_addr: 'c', to_addr; '3'}] AS row
MERGE (a:utest {id:row.from_addr})-[:SENT {val:row.val}]->(b:utest {id:row.to_addr})

Okay this is really useful! Thank you so much! =D

1 Like

No problem, I'm glad it helps you:)

1 Like