Graph database creation using Neo4j - Airline example

Viewed 71

I am trying to create a neo4j graph database from the below csv:

enter image description here

I am finding it hard to figure out the different nodes and relationships.

I tried the below code but the database was not connected like it needs to be.

LOAD CSV WITH HEADERS FROM 'file:///dummy.csv' AS row
MERGE (a: Airport {depatureId: row.Origin, arrivalId: row.Dest})
MERGE (f: Flight {flightId: row.Flight_num, distance: row.Distance, Flightdate: row.Date, Flightdelay: row.Total_delay, Airline: row.Carrier_code})
MERGE (a)-[r1:HAS_FLIGHT]->(f)
MERGE (f)-[r2:FLYING_TO]->(a)

Another attempt

LOAD CSV WITH HEADERS FROM 'file:///dummy.csv' AS row
MERGE (o: Origin {origin_airportId: row.Origin})
MERGE (d: Destination {destination_airportId: row.Dest})
MERGE (f: Flight {flightId: row.Flight_num, distance: row.Distance, Flightdate: row.Date, Flightdelay: row.Total_delay, Airline: row.Carrier_code})
MERGE (o)-[r1:FLYING_FROM]->(f)
MERGE (f)-[r2:FLYING_TO]->(d)

Any ideas or suggestions would be much appreciated, thanks.

1 Answers

I use data types when loading csv: toInteger(row.nbr), toFloat(), toString(), toBoolean, etc. To debug your loading you might try loading specific items to see if a specific merge is messed up.

Have you set up indexes so the loads are faster? Is your file in the Neo4j Import directory?

The relationships you are merging are not set up correctly. They should be done in a separate load looking something line this:

    LOAD CSV WITH HEADERS FROM 'file:///dummy.csv' AS row
    MATCH (o: Origin {origin_airportId: toString(row.Origin)})
    MATCH (f: Flight {flightId: toInteger(row.Flight_num)})
    MERGE (o)-[r1:FLYING_FROM]->(f)
Related