Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-10-2020 10:29 AM
Hi everybody,
this is the 1st time I'm using APOC.
I'm trying the below query with APOC but experiencing some errors.
I'd really appreciate help fixing/organizing my query.
Note: without the use of APOC, all works fine.
call apoc.periodic.iterate(
"MATCH (s1:s) WITH s1 MATCH (e1:e) WHERE s1.id = 'OG.O.CL-2.0.0.0.21.13.1' AND e1.id = 'Corporate' MERGE (s1)-[r:POLICY_TO_TAG]->(e1)",
"ON MATCH SET r.id='56482bc3-9f40-4873-a5c6-b9294e14e8dc', r.name=null RETURN r.id as id, type(r) as type, s1 as startnode, e1 as endnode, labels(s1) as startlabel, labels(e1) as endlabel, r.name as name",
{batchSize:10000, parallel:true})
Thanks in advance,
Boris
11-11-2020 03:09 AM
CALL apoc.periodic.iterate(
"MATCH (s1:s)
MATCH (e1:e)
WHERE s1.id = 'OG.O.CL-2.0.0.0.21.13.1' AND e1.id = 'Corporate'
RETURN s1, e1",
"MERGE (s1)-[r:POLICY_TO_TAG]->(e1)
ON MATCH SET r.id='56482bc3-9f40-4873-a5c6-b9294e14e8dc', r.name=null",
{batchSize:10000, parallel:true})
11-11-2020 03:22 AM
Thanks, @lemoupasimon, the execution of this query doesn't error.
Said that it does not insert anything to the graph
11-11-2020 04:14 AM
If there is no previous POLICY_TO_TAG relation between s1 and e1 nodes, there will be no insertion due to ON MATCH SET clause. Maybe you should add ON CREATE SET clause to cover that case. Some thing like this:
CALL apoc.periodic.iterate(
"MATCH (s1:s)
MATCH (e1:e)
WHERE s1.id = 'OG.O.CL-2.0.0.0.21.13.1' AND e1.id = 'Corporate'
RETURN s1, e1",
"MERGE (s1)-[r:POLICY_TO_TAG]->(e1)
ON MATCH SET r.id='56482bc3-9f40-4873-a5c6-b9294e14e8dc', r.name=null
ON CREATE SET r.id='56482bc3-9f40-4873-a5c6-b9294e14e8dc', r.name=nul",
{batchSize:10000, parallel:true})
11-11-2020 03:28 AM
This is what I found to be working:
call apoc.periodic.iterate(
"MERGE (s1:s{id:'OG.O.CL-2.0.0.0.21.13.1'})
WITH s1
MERGE (e1:e{id:'Corporate'})
MERGE (s1)-[r:POLICY_TO_TAG]->(e1)
RETURN r",
"SET r.id='56482bc3-9f40-4873-a5c6-b9294e14e8dc', r.name=null",
{batchSize:10000, parallel:true, iterateList:true})
But I don't see the logic of it. I.e. why not use something more reasonable like @lemoupasimon wrote above.
All the sessions of the conference are now available online