# Creating relationships efficiently using Apoc

**URL:** <https://community.neo4j.com/t/creating-relationships-efficiently-using-apoc/53433>\
**Category:** Cypher\
**Tags:** apoc, performance, import\
**Created:** [March 15, 2022, 6:34pm UTC](https://community.neo4j.com/t/creating-relationships-efficiently-using-apoc/53433 "2022-03-15T18:34:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![starz10de](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/starz10de/32/3933_2.png) [@starz10de](https://community.neo4j.com/u/starz10de)\
**Post date:** [March 15, 2022, 6:34pm UTC](https://community.neo4j.com/t/creating-relationships-efficiently-using-apoc/53433/1 "2022-03-15T18:34:18Z")

</div>

I have a graph containing many nodes. Each node in the graph has the same properties with different values. I loaded the graph efficiently using:

```auto
CALL apoc.periodic.iterate('LOAD CSV FROM $url AS data FIELDTERMINATOR "," return data',
'CREATE (:G {x: data[0],y: data[1]})'
,{batchSize:1000, iterateList:true, parallel:trueparams:{url:"file:///file.csv"}});

```

I indexed the nodes based on properties.  
I wanted to link nodes based on similar property value. I used:

```auto
MATCH (a:G )
MATCH (b:G)
WHERE a.x= b.y
MERGE (a)-[:similar]->(b)
RETURN *

```

However, this solution is very slow, is there any hints about other way to do this? Also is it possible to create the relationships during the data loading inside the `CALL apoc.periodic.iterate` block ?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [March 15, 2022, 7:42pm UTC](https://community.neo4j.com/t/creating-relationships-efficiently-using-apoc/53433/2 "2022-03-15T19:42:26Z")

</div>

I guess it is taking some time because it has to evaluate each node against every other node to find a match. If you have N nodes, it would be N\*N comparisons since symmetry counts and it will compare each node to itself.

The issue I see with you combining the node and relationship creation is that you need to create the two nodes first and I assume the order of your import file is random.

Can you rearrange your import file so each line contains the two matching nodes.
