Iterate through two lists?

I'm trying to associate two lists, in a one-to-one relationship.
This query is returning the following: all objects in p are merged with only the first element of r.
I need something like id1(n)-[:HAS_ID]-id2(n)

MATCH p=(n:ID1)

MATCH r=(o:ID2)

WITH p, r LIMIT 100

UNWIND nodes(p) AS ids1

UNWIND nodes(r) AS ids2

MERGE (ids1)-[:HAS_ID]->(ids2)

Hello @andreperez :slight_smile:

MATCH (a:ID1)
WITH a LIMIT 100
WITH collect(a) AS ids1
MATCH (b:ID2)
WITH ids1, b LIMIT 100
WITH ids1, collect(b) AS ids2
UNWIND range(0, size(ids1)) AS i
MERGE (ids1[i])-[:HAS_ID]->(ids2[i])

Regards,
Cobra

1 Like

Your query makes total sense to me, but Neo4J is complaining D:

Invalid input 'ids1': expected "(", "allShortestPaths" or "shortestPath" (line 8, column 8 (offset: 175))
"MERGE (ids1[i])-[:HAS_ID]->(ids2[i])"
        ^

MATCH (a:ID1)
WITH a LIMIT 100
WITH collect(a) AS ids1
MATCH (b:ID2)
WITH ids1, b LIMIT 100
WITH ids1, collect(b) AS ids2
UNWIND range(0, size(ids1)-1) AS i
WITH ids1[i] AS n, ids2[i] AS m
MERGE (n)-[:HAS_ID]->(m)
2 Likes

Thank you, works perfectly

1 Like