Importing CSV data into Neo4j
Write Cypher that imports CSV data into Neo4j. Create nodes and relationships with LOAD CSV, cast data types, and batch large imports in transactions.
In this 1-hour course, you will learn
Visual import tools get you a long way, but the moment your data needs cleaning, reshaping, or conditional logic on the way into the graph, you want to write the import yourself. This course teaches you to import CSV data into Neo4j using Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it., giving you row-by-row control over how flat files become Full definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties., Full definition for relationship (opens in a new tab)A named, directed connection between two nodes. Every relationship has a type, a start node and an end node., and Full definition for property (opens in a new tab)A named value stored on a node or a relationship..
Over roughly an hour, you will build a graph of movies, people, and ratings from a set of CSV files. You will write LOAD CSV statements by hand, decide exactly which columns become properties and which become relationships, cast string values to the correct data types, split delimited fields into lists, and apply additional Full definition for label (opens in a new tab)A tag on a node that groups it with other nodes of the same kind. A node can carry more than one. based on the data in each row.
How to Import CSV Data into Neo4j
Learn to load structured CSV files directly into Neo4j using the LOAD CSV clause, mapping columns to graph properties with precise field references.
Using LOAD CSV and Cypher
Write LOAD CSV statements combined with MERGE and CREATE to build nodes and relationships from flat file data in a single Cypher query.
Creating a Data Model
Design a graph data model from a relational CSV dataset, identifying entities as nodes and associations as typed relationships before writing import queries.
Neo4j Data Types and How to Cast Data
Apply built-in conversion functions such as toInteger(), toFloat(), and date() to cast raw CSV strings into the correct Neo4j property types.
How Transactions Affect Data Importing and How to Manage Them
Understand how Neo4j batches writes in transactions and use CALL { ... } IN TRANSACTIONS to safely import large CSV files without exhausting heap memory.
4 modules, 1 hour.
Who this course is for
This course is for developers and data engineers who want full control over how data enters Neo4j: you have used the Full definition for Data Importer (opens in a new tab)The Neo4j tool for loading CSV files into a graph by mapping their columns onto nodes and relationships. and hit its limits, or you need an import you can script, version, review, and re-run as part of a pipeline. It also suits anyone preparing to load their own data, which arrives with inconsistent types, multi-value columns, and rows that map to more than one Full definition for label (opens in a new tab)A tag on a node that groups it with other nodes of the same kind. A node can carry more than one. - this course deals with each of those problems directly. You should be comfortable with the basics from Neo4j Fundamentals, Cypher Fundamentals, and Graph Data Modeling Fundamentals before you start; if you want a gentler introduction to importing first, take Importing Data Fundamentals.
What you'll do
This is a hands-on course. You will work in an empty Neo4j instance and build the graph yourself, one Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. statement at a time. You will start by inspecting the source CSV files and understanding how their structure maps onto a graph model, write
LOAD CSVclauses that read files by URL and iterate over rows, then point the same syntax at a CSV file of your own to prove the technique transfers.From there you will create
MovieandPersonFull definition for node (opens in a new tab)A vertex in a graph. In a property graph it can carry labels and properties. withMERGE, define unique identifiers backed by Full definition for constraint (opens in a new tab)A rule the database enforces on every node or relationship with a given label or type, rejecting any write that breaks it., and connect nodes withACTED_INandDIRECTEDFull definition for relationship (opens in a new tab)A named, directed connection between two nodes. Every relationship has a type, a start node and an end node.. You will improve the data quality of what you have loaded: casting numeric strings withtoInteger()andtoFloat(), converting date strings to date values, splitting a delimited column into a list Full definition for property (opens in a new tab)A named value stored on a node or a relationship., and adding an extraDirectorFull definition for label (opens in a new tab)A tag on a node that groups it with other nodes of the same kind. A node can carry more than one.. Finally, you will confront larger imports: batching work withCALL { ... } IN TRANSACTIONSso a million-row file does not exhaust memory, and splitting an import into multiple passes to avoid the Eager operator.Where to go next
With the fundamentals of Cypher-based importing in place, LOAD CSV Data Import is a hands-on lab where you build a complete import pipeline, including idempotent statements you can safely re-run and techniques for handling missing data, and Cypher Intermediate Queries sharpens the query skills you will use to validate the data you import. Importing data with Full definition for Cypher (opens in a new tab)Neo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it. is also covered on the Neo4j Certified Professional exam, so completing this course moves you a step closer to certification.
Posts from the GraphAcademy blog.
My five favorite cards in Aura Dashboards
When Dashboards first became available in Aura, I started to move my reporting away from custom tools. Here are the five cards I use the most, and a Cypher statement behind them.
SQL to Cypher - 10 Queries You Already Know
You already know how to write these queries. This article shows you what they look like when the joins go away.
Writing Cypher Queries That Don't Lose Your Data
The query trap that hides your newest data, and the query shape that brings it back.