# Create large amount of relationships \[not enough memory\]

**URL:** <https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132>\
**Category:** Desktop\
**Tags:** cypher, relationship\
**Created:** [August 8, 2020, 7:58pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132 "2020-08-08T19:58:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadavbe](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nadavbe/32/14414_2.png) [@nadavbe](https://community.neo4j.com/u/nadavbe)\
**Post date:** [August 8, 2020, 7:58pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/1 "2020-08-08T19:58:09Z")

</div>

I got this large dataset (~1M nodes) of actions, each is attributed to some user id ("id") and phase\_index that indicates a chronological order.  
I want to create a relationship within these nodes, in order to draw a path for each id, based on the order of the index.  
When trying to create this in a simple way, I get a not enough memory error.  
And idea on how to iterate on this, so that each id will build its entire path?

---

<div class="post-metadata">

**Author:** ![jggomez](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jggomez/32/7793_2.png) [@jggomez](https://community.neo4j.com/u/jggomez)\
**Post date:** [August 8, 2020, 8:05pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/2 "2020-08-08T20:05:35Z")

</div>

Hi, How are you doing those relationships? are you using UNWIND??

Thanks

---

<div class="post-metadata">

**Author:** ![nadavbe](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nadavbe/32/14414_2.png) [@nadavbe](https://community.neo4j.com/u/nadavbe)\
**Post date:** [August 8, 2020, 8:08pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/3 "2020-08-08T20:08:24Z")

</div>

This is what I currently use:  
MATCH (a1:Actions)  
WITH a1  
match (a2:Actions{id:a1.id, phase\_index:a1.phase\_index+1})  
merge (a2)\<-[:JOURNEY\_PHASE]-(a1)

---

<div class="post-metadata">

**Author:** ![jggomez](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jggomez/32/7793_2.png) [@jggomez](https://community.neo4j.com/u/jggomez)\
**Post date:** [August 8, 2020, 8:27pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/4 "2020-08-08T20:27:48Z")

</div>

Hi, You could try periodic commits.

You can read the following information:  
[https://neo4j.com/docs/labs/apoc/current/graph-updates/periodic-execution/](https://neo4j.com/docs/labs/apoc/current/graph-updates/periodic-execution/)

Thanks

---

<div class="post-metadata">

**Author:** ![nadavbe](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nadavbe/32/14414_2.png) [@nadavbe](https://community.neo4j.com/u/nadavbe)\
**Post date:** [August 8, 2020, 9:28pm UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/6 "2020-08-08T21:28:40Z")

</div>

I'm pretty new to this. Using desktop and seeing some examples online, this is what I came up with, though I'm really not sure what the last return is for. Anyways, it's running for a long time (and no conclusion yet). Any comments on my implementation? Thanks!

call apoc.periodic.commit(  
"MATCH (a1:Product)  
WITH a1 limit $limit  
match (a2:Product{id:a1.id, phase\_index:a1.phase\_index+1})  
merge (a1)-[:JOURNEY\_PHASE]-\>(a2)  
return count(\*)",  
{limit:100000})

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [August 10, 2020, 6:50am UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/7 "2020-08-10T06:50:25Z")

</div>

Hello @nadavbe 🙂

I think 100000 as limit is too big, you should use 10000 or 1000 🙂

```auto
call apoc.periodic.commit("
MATCH (a1:Product)
WITH a1 limit $limit
MATCH (a2:Product{id:a1.id, phase_index:a1.phase_index+1})
MERGE (a1)-[:JOURNEY_PHASE]->(a2)
RETURN count(*)
", {limit:1000})

```

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![nadavbe](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nadavbe/32/14414_2.png) [@nadavbe](https://community.neo4j.com/u/nadavbe)\
**Post date:** [August 10, 2020, 7:17am UTC](https://community.neo4j.com/t/create-large-amount-of-relationships-not-enough-memory/23132/8 "2020-08-10T07:17:50Z")

</div>

Hi @Cobra,  
Actually, I let it run for a while and query the nodes while running.  
It seemed to be stuck on some number and never advance, for a reason I can't understand.  
I then tried to periodic iterate instead and it worked pretty quickly.  
To me it looks like both methods should provide the same results, but for some reason only iterate worked for me.  
But at least I solved it :)
