Using neo4j-import with existing database in Neo4j Desktop


(Michael McKenzie) #1

I have used neo4j-import when running Neo4j locally through command line. Lately I have been using Neo4j Desktop mostly lately to switch between multiple projects. I have a LOAD CSV cypher file created and have used it to import one csv file that works really well. However, I have approximately 100 or so additional csv files that I would like to import into an existing database.

Is it possible to use neo4j-import with an existing database, or possibly a way to use LOAD CSV? Each file contains at least 10,000+ rows with ~200 columns each, so I will need to use PERIODIC COMMIT.

This Stack Overflow Article seemed promising, but appears to indicate issues with using PERIODIC COMMIT.


(Michael Hunger) #2

neo4j-import cannot be used with existing databases

you can use apoc.perodic.iterate

call apoc.periodic.iterate("
unwind $files as file
load csv with headers from file as row return row",
"create (p:Person  {name:row.name}) ...",
{batchSize:10000,iterateList:true});

(Michael McKenzie) #3

Thanks @michael.hunger! i will check that out


(Michael McKenzie) #4

@michael.hunger Just wanted to update you and let you know that worked perfectly. I was able to import 2 files to make sure I had the progress down. Thanks again


(SunPark) #5

@michael.hunger I'd like to use apoc.periodic.iterate with flights_50k.csv which file from GraphConnect2017 import training.

call apoc.periodic.iterate("
unwind $files as file
load csv with headers from file as row return row",
"create (p:Person {name:row.name}) ...",
{batchSize:10000,iterateList:true});

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///flights_50k.csv" AS row
MERGE (origin:Airport {code: row.Origin})
MERGE (destination:Airport {code: row.Dest})
WITH row.UniqueCarrier + row.FlightNum + "" + row.Year + "-" + row.Month + "-" + row.DayofMonth + "" + row.Origin + "_" + row.Dest AS flightIdentifier, row, origin, destination
MERGE (flight:Flight { id: flightIdentifier })
ON CREATE SET flight.date = row.Year + "-" + row.Month + "-" + row.DayofMonth,
flight.airline = row.UniqueCarrier, flight.number = row.FlightNum, flight.departure = row.CRSDepTime,
flight.arrival = row.CRSArrTime, flight.distance = row.Distance, flight.cancelled = row.Cancelled
MERGE (flight)-[:ORIGIN]->(origin)
MERGE (flight)-[:DESTINATION]->(destination)

I tried to merge apoc.periodic,iterate and LOAD CSV~~.
However, I failed with below ERROR

FROM
call apoc.periodic.iterate("
load csv with headers from "file:///flight_init.csv" as row return row",
"MERGE (origin:Airport {code: row.Origin})
MERGE (destination:Airport {code: row.Dest})
WITH row.UniqueCarrier + row.FlightNum + "" + row.Year + "-" + row.Month + "-" + row.DayofMonth + "" + row.Origin + "_" + row.Dest AS flightIdentifier, row, origin, destination
MERGE (flight:Flight { id: flightIdentifier })
ON CREATE SET flight.date = row.Year + "-" + row.Month + "-" + row.DayofMonth,
flight.airline = row.UniqueCarrier, flight.number = row.FlightNum, flight.departure = row.CRSDepTime,
flight.arrival = row.CRSArrTime, flight.distance = row.Distance, flight.cancelled = row.Cancelled
MERGE (flight)-[:ORIGIN]->(origin)
MERGE (flight)-[:DESTINATION]->(destination)",
{batchSize:10000,iterateList:true});

WHAT're wrong with me?


(SunPark) #6

I'd like to use apoc.periodic.iterate with flights_50k.csv which file from GraphConnect2017 import training.

call apoc.periodic.iterate("
unwind $files as file
load csv with headers from file as row return row",
"create (p:Person {name:row.name}) ...",
{batchSize:10000,iterateList:true});

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///flights_50k.csv" AS row
MERGE (origin:Airport {code: row.Origin})
MERGE (destination:Airport {code: row.Dest})
WITH row.UniqueCarrier + row.FlightNum + " " + row.Year + "-" + row.Month + "-" + row.DayofMonth + " " + row.Origin + "_" + row.Dest AS flightIdentifier, row, origin, destination
MERGE (flight:Flight { id: flightIdentifier })
ON CREATE SET flight.date = row.Year + "-" + row.Month + "-" + row.DayofMonth,
flight.airline = row.UniqueCarrier, flight.number = row.FlightNum, flight.departure = row.CRSDepTime,
flight.arrival = row.CRSArrTime, flight.distance = row.Distance, flight.cancelled = row.Cancelled
MERGE (flight)-[:ORIGIN]->(origin)
MERGE (flight)-[:DESTINATION]->(destination)

I tried to merge apoc.periodic,iterate and LOAD CSV~~.
However, I failed with below ERROR


FROM
call apoc.periodic.iterate("
load csv with headers from "file:///flight_init.csv" as row return row",
"MERGE (origin:Airport {code: row.Origin})
MERGE (destination:Airport {code: row.Dest})
WITH row.UniqueCarrier + row.FlightNum + " " + row.Year + "-" + row.Month + "-" + row.DayofMonth + " " + row.Origin + "_" + row.Dest AS flightIdentifier, row, origin, destination
MERGE (flight:Flight { id: flightIdentifier })
ON CREATE SET flight.date = row.Year + "-" + row.Month + "-" + row.DayofMonth,
flight.airline = row.UniqueCarrier, flight.number = row.FlightNum, flight.departure = row.CRSDepTime,
flight.arrival = row.CRSArrTime, flight.distance = row.Distance, flight.cancelled = row.Cancelled
MERGE (flight)-[:ORIGIN]->(origin)
MERGE (flight)-[:DESTINATION]->(destination)",
{batchSize:10000,iterateList:true});

WHAT're wrong with me?


(SunPark) #7

I tried with below.

$files = "file:///flight_init.csv"
call apoc.periodic.iterate("
UNWIND $files as file
load csv with headers from file as row return row",
{batchSize:10000,iterateList:true});

But, I've got error.


(Michael Hunger) #8

The quotes are wrong, you cannot use " within " without escaping them e.g. \" or by using single quotes ' inside of the statement.