2
votes

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
Please edit your question to be more specific: what's wrong when you run the loads you mentioned? Also, please edit your sample csv to be formatted text, not an image of text. This meta post lists many reasons why this is important. Lastly, this has nothing to do with olap or cubes (referenced by your tags). I removed these tags, accordingly.David Makogon
May be, you should MERGE Flight node with only a pattern of flightId, and other properties should be set by a SET clause?norihide.shimatani

1 Answers

0
votes

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)