Nicolapo
Nicolapo

Reputation: 49

Speed up Neo4j relationship creation

I have a CSV file with 1 million rows and 3 columns (NODE_ID_1, PROPERTY_COLUMN, NODE_ID_2).
I also have an already existing Neo4j database containing Node label. I should create the relationship RELATED_TO between nodes. I use the following cypher query to create the relationship between nodes but it is too cumbersome (it takes more than a day to complete the rel creation). Do you have some tips to quickly generate the relationship?


         CALL apoc.periodic.iterate(
        "LOAD CSV WITH HEADERS FROM $url AS row 
         WITH row {.*, PROPERTY: toFloat(row.PROPERTY_COLUMN)}
         RETURN row",
        "MATCH (src:Node {node_id : row['NODE_ID_1']}), (dst:Node {node_id : row['NODE_ID_2']}) 
         MERGE (src)-[r:RELATED_TO]-(dst)
         SET r += {property_column: row['PROPERTY_COLUMN']}
        ",
        {batchSize: 1000, batchMode: "BATCH", parallel:false, params: {url: 'file:///path_to_file'} })

Upvotes: 0

Views: 419

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30397

Do you have an index on :Node(node_id)? You NEED this for your MATCH operations to be performant.

https://neo4j.com/docs/cypher-manual/current/administration/indexes-for-search-performance/

Upvotes: 1

Related Questions