I am aware of the Import tool but in my case i have to read a row and break it down into nodes and relationships . Using the load csv query with periodic commit with indexes and ,to import 2Million rows its taking more than 12 hours. Is there a way for me to use above mentioned tool with out having to preprocess the csv into nodes and relationships?
Following is the sample query i use
CREATE INDEX ON :Patient(mrno);
CREATE INDEX ON :Location(city);
CREATE INDEX ON :Department(id);
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///home/geralt/Desktop/Temp_Admission.csv" AS line
WITH line,
(CASE WHEN line.MRNo='' OR line.MRNo='null' THEN "BLEH" ELSE line.MRNo END, "NA") AS mrn,
(CASE WHEN line.ID_Admit='' OR line.ID_Admit='NULL' THEN -1 ELSE line.ID_Admit END,0) AS ID_Admit,
(CASE WHEN line.DeptCode_Admit='' OR line.DeptCode_Admit='NULL' THEN -1 ELSE line.DeptCode_Admit END,0) AS DeptCode_Admit,
(CASE WHEN line.City='' OR line.City='NULL' THEN "BLEH" ELSE line.City END,"NA") AS city
MERGE (p:Person { mrn: mrn}) ON MATCH SET p.DOB=line.DateOfBirth,p.gender=line.GenderDescription,p.prefix=line.PrefixDescription ON CREATE SET p.DOB=line.DateOfBirth,p.gender=line.GenderDescription,p.prefix=line.PrefixDescription
CREATE (a:Admission{HospitalName:line.Hospital,id:toInt(ID_Admit),unitId:line.UnitID_Admit,IPDNo:line.IPDNO,DateOfAdmission:line.Date_Admit})
MERGE(d:Department{id:toInt(DeptCode_Admit)}) ON MATCH SET d.name=line.DeptName_Admit
MERGE(l:Location{city:city}) ON MATCH SET l.country=line.Country,l.state=line.State
merge p-[:Admitted]->a
MERGE a-[:Located]->l
It should be pretty straightforward to just do multiple runs (you can even do those in parallel-with multiple browser or neo4j-shell sessions).
ON MATCH SET
:Person(mrno), :Admission(id)
ON CREATE SET
WITH
with only the fields you want to import, see DepartmentHere is your fixed / full / multiple-run import script: