Search code examples
csvneo4jpy2neo

Neo4j relationship not getting added using Load csv


I am trying to use the Load csv method of neo4j. I have successfully added all the nodes to neo4j. But when it comes to relationships , the cypher statements run without any errors but they are never getting added and are not visible in the browser. But nodes can be seen just fine. Below are my CSVs.

First is the Customer.csv and second is customer_send.csv

         Galactic_ID:ID(Customer),:LABEL
 1000000000036666531,Customer
 2000000000198737143,Customer
 2000000000101281958,Customer
 1000000000281474324,Customer
 1000000000073478335,Customer
 1000000000283083892,Customer
 2000000000230105092,Customer
 1000000000287320588,Customer
 1000000000020059606,Customer


    :START_ID(Customer),:END_ID(Customer),TXN_KEY,Amount,SendTime,PayTime,:TYPE
1000000000036666531,1000000000089771041,5000000000107593411,20.0,1361439,1362963.0,Customer_Send
2000000000198737143,2000000000181818203,5000000000108495674,220.0,1361434,1362369.0,Customer_Send
2000000000101281958,1000000000210500686,5000000000106488543,1000.0,1361435,1363053.0,Customer_Send
1000000000281474324,2000000000246874104,5000000000106029876,1669.0,1361424,1362506.0,Customer_Send
1000000000073478335,2000000000200242093,5000000000107872144,180.0,1361415,1362680.0,Customer_Send
1000000000283083892,2000000000258949202,5000000000107701034,156.0,1361414,1362738.0,Customer_Send
2000000000230105092,1000000000064145673,5000000000105488820,329.0,1361392,1362558.0,Customer_Send
1000000000287320588,1000000000287658165,5000000000105281335,620.0,1361391,1362365.0,Customer_Send
1000000000020059606,1000000000046608791,5000000000105081275,65.0,1361389,1363317.0,Customer_Send

Below are my cypher statements:

In [24]: stmt6 = """USING PERIODIC COMMIT LOAD CSV FROM "file:///mnt/database/Neo/db3/import_data1/customer.csv" AS csvLine
 ....: MERGE (c:Customer {Galactic_ID:csvLine[0]})
 ....: ON CREATE SET c.Galactic_ID = csvLine[0]"""

    stmt3 = """USING PERIODIC COMMIT LOAD CSV     FROM"file:///mnt/database/Neo/db3/import_data1/customer_send.csv" AS csvLine
 Match (a:Customer {Customer:csvLine[0]}), (c:Customer {Customer:csvLine[1]})
 Merge (a)-[r:Customer_Send]->(c)
 On Create SET r.TXN_KEY = csvLine[2], r.Amount = csvLine[3], r.SendTime = csvLine[4], r.PayTime = csvLine[5]"""


graph.cypher.execute(stmt6)

graph.cypher.execute(stmt3)

First graph stmt to create Customer node runs fine and node is created and visible in the graph. Second stmt runs for a while and ends without any errors but no relationship is created.


Solution

  • Try to match nodes on the property on which you create them:

    Match (a:Customer {Customer:csvLine[0]}), (c:Customer {Customer:csvLine[1]})
    
    =>
    
    Match (a:Customer {Galactic_ID:csvLine[0]}), (c:Customer {Galactic_ID:csvLine[1]})