cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

MATCH not meeting a MERGE inside the same UNWIND...

Here's a mysterious one... spent hours trying to find the bug and I give up.

We basically parse a json file with a list of 

[{emailAddress:["emmanuel.lefort@louisa.com"],displayName:"Emmanuel",nodeID:319463},
{emailAddress:["emmanuel.lefort@louisa.com"],displayName:"Emmanuel",nodeID:1233445}] with multiple same emailAddress and displayName.
 
The below query is supposed to create an Email node and attach it to an Alias node with a ":HAS_ALIAS" link.
 
But strangely, the query fails to MATCH a node that was MERGED during the same process. In other words, if we run the query one line by one line, it works well and there is only one Alias node created for each displayName. If we run the query for the whole batch, there are as many aliases as there are lines: the query doesnt MATCH the Alias that has just been created.
 
Am I missing something here ? Is there a way to force Neo4J to commit the MERGE before trying the MATCH ?

 

// IMPORT EMAIL QUERY
CALL apoc.load.json('TestEmails.json') YIELD value AS batch
WITH batch
UNWIND batch as row
WITH row SKIP 0 LIMIT 100
FOREACH (emailAddress in row.emailAddress |
MERGE (e:Email { nodeID: emailAddress })
SET e.updateDate = timestamp() )
WITH row
OPTIONAL MATCH (aliasFound:Alias { displayName: row.displayName })<-[:HAS_ALIAS]-(e:Email) WHERE e.nodeID IN row.emailAddress
WITH aliasFound, row
MERGE (n:Alias { nodeID: COALESCE(aliasFound.nodeID, COALESCE(row.nodeID, apoc.create.uuid())), displayName: row.displayName })
ON CREATE SET n.nodeID = row.nodeID
 
WITH n, row, aliasFound
OPTIONAL MATCH (e:Email) WHERE e.nodeID IN row.emailAddress
FOREACH(ignoreMe IN CASE WHEN e IS NOT NULL THEN [1] ELSE [] END |
MERGE (e)-[ex:HAS_ALIAS]->(n)
)
RETURN *

 

0 REPLIES 0