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.

Improve match of two sets of nodes

JuSte94
Node Link

Hello,
I have two labels (commits and users).
In the commits I have the ID of the committer as Int (committer-id).
I want to create a simple relationship between the committer and the user (u.id).
My solution looks like this:

match(c:commits)
with c
match(u:users)
where c.committer_id = u.id
create(c)-[:committer]->(u) 

My current problem is that is takes a long time to create this relationship.
I added an index the committer_id, but it didn't improve my query.
Any Idea of improvements?

Constraints:

Settings:

dbms.memory.heap.initial_size=8G
dbms.memory.heap.max_size=8G
dbms.memory.pagecache.size=5G
1 ACCEPTED SOLUTION

Hello @JuSte94 and welcome to the Neo4j community

You should try with the apoc.periodic.iterate() function in the APOC plugin:

CALL apoc.periodic.iterate(
  "MATCH (u:users) MATCH (c:commits) WHERE c.committer_id = u.id RETURN c, u",
  "CREATE (c)-[:committer]->(u)",
  {batchSize: 10000}
)

Regards,
Cobra

View solution in original post

2 REPLIES 2

Hello @JuSte94 and welcome to the Neo4j community

You should try with the apoc.periodic.iterate() function in the APOC plugin:

CALL apoc.periodic.iterate(
  "MATCH (u:users) MATCH (c:commits) WHERE c.committer_id = u.id RETURN c, u",
  "CREATE (c)-[:committer]->(u)",
  {batchSize: 10000}
)

Regards,
Cobra

Hey @Cobra

thank you. Worked well