# Very slow cypher queries to create relationships

**URL:** <https://community.neo4j.com/t/very-slow-cypher-queries-to-create-relationships/30506>\
**Category:** Import / Export\
**Tags:** apoc, performance, browser, relationship\
**Created:** [December 16, 2020, 6:08pm UTC](https://community.neo4j.com/t/very-slow-cypher-queries-to-create-relationships/30506 "2020-12-16T18:08:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chauhan.ishan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/chauhan.ishan/32/15565_2.png) [@chauhan.ishan](https://community.neo4j.com/u/chauhan.ishan)\
**Post date:** [December 16, 2020, 6:08pm UTC](https://community.neo4j.com/t/very-slow-cypher-queries-to-create-relationships/30506/1 "2020-12-16T18:08:42Z")

</div>

Hey guys,

I am experimenting with the community edition of neo47 using the browser application. We may move onto the enterprise one but there's a roadblock that I am seeing. Here's my problem:

I imported and creates 1.5 million+ nodes with 20 metadata properties using APOC. Now, I need to create relationships between approx 250k of these service nodes. I am using APOC to do that and the data is in python dictionary(json) format in the code. The queries are extremely slow, it took 4-5 hours just to get 20k relationships build out. Here's my query:

query = '''  
CALL apoc.periodic.iterate("UNWIND $relationship\_list as individual\_service RETURN individual\_service",  
"MATCH (parent\_service:Service\_Asset\_ID), (child\_service:Service\_Asset\_ID) WHERE parent\_service.id=individual\_service.parent AND child\_service.id=individual\_service.child AND parent\_service.source=child\_service.source MERGE (parent\_service)-[:SERVICED\_BY]-\>(child\_service) ",  
{batchSize:1000, iterateList:true, parallel:true, params: {relationship\_list:$relationship\_list}})  
'''  
I have tried to follow up on some of the best practices but to no avail. I have also indexed the id and source fields. Any suggestions ?

Neo4j version: 4.1.3  
I am using python driver

Thanks,  
Ishan

---

<div class="post-metadata">

**Author:** ![TonyOD27](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tonyod27/32/5200_2.png) [@TonyOD27](https://community.neo4j.com/u/TonyOD27)\
**Post date:** [December 16, 2020, 6:20pm UTC](https://community.neo4j.com/t/very-slow-cypher-queries-to-create-relationships/30506/2 "2020-12-16T18:20:01Z")

</div>

Hi Ishan,

I had a similar issue. What solved this problem for me was using the neo4j-admin import tool to create both, nodes and relationships, at the same time. Here are the docs: [Import - Operations Manual](https://neo4j.com/docs/operations-manual/current/tools/import/)

Creating millions of nodes was not a problem for me using APOC or LOAD CSV. However, the APOC functions were taking more than 6 hours to create the relationships between a subset of 300,000 nodes.

If you're already working in Python, then creating the csv files for the neo4j-admin import tool should not be too difficult. Pandas was pretty much all I needed for this and the neo4j-admin import tool took about 30 minutes to create all of my nodes and relationships.

I hope this helps. Best of luck.

-Tony
