简体   繁体   中英

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'} })

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM