Skip to main content
Version: 1.6.1

LOAD CSV Cypher clause

The LOAD CSV clause enables you to load and use data from a CSV file of your choosing in a row-based manner, within a query. We support the Excel CSV dialect, as it's the most commonly used one. For the syntax of the clause, please check the Cypher manual.

The clause reads row by row from a CSV file and binds the contents of the parsed row to the variable you specified.

For more detailed information about the LOAD CSV Cypher clause, check

To work with the LOAD CSV clause, we need to have access to our files. If working with Docker, check our Docker guide on how to access files from your local filesystem:

Below, you can find two examples of how to use the CSV Import Tool depending on the complexity of your data:

Examples​

One type of nodes and relationships​

Depending on how you set the HEADER option (WITH or NO), a row will be parsed as either a map or a list.

To access a given field, you can use the property lookup syntax. Let's assume that the contents of people_nodes.csv are as follows:

id,name
100,Daniel
101,Alex
102,Sarah
103,Mia
104,Lucy

The contents of people_relationships.csv are the following:

id_from,id_to
100,101
100,102
100,103
101,103
102,104

The following query will load row by row from the file, and create a new node for each row with properties based on the parsed row values:

LOAD CSV FROM "/path-to/people_nodes.csv" WITH HEADER AS row
CREATE (n:Person {id: row.id, name: row.name});

With the initial nodes in place, you can now create relationships between them:

LOAD CSV FROM "/path-to/people_relationships.csv"  WITH HEADER AS row
MATCH (p1:Person {id: row.id_from}), (p2:Person {id: row.id_to})
CREATE (p1)-[:IS_FRIENDS_WITH]->(p2)

Multiple types of nodes and relationships​

In the case of a more complex graph, we have to deal with multiple node and relationship types. Let's assume we have the following example:

Add the following to the file people_nodes.csv:

id,name,age,city
100,Daniel,30,London
101,Alex,15,Paris
102,Sarah,17,London
103,Mia,25,Zagreb
104,Lucy,21,Paris

The following query will load row by row from the file, and create a new node for each row with properties based on the parsed row values:

LOAD CSV FROM "/path-to/people_nodes.csv" WITH HEADER AS row
CREATE (n:Person {id: row.id, name: row.name, age: ToInteger(row.age), city: row.city});