Unable to load CSV file into Neo4j

Viewed 2883

I've just started using Neo4j and have attempted to follow tutorials on YouTube about how to inport CSVs into Neo4j.

I am using the code below to try and import my CSV onto Neo4j by using Cypher:

LOAD CSV WITH HEADERS FROM "file:/Users/MATT/Documents/LL.csv" As csvline
MATCH(n) RETURN n

However, I keep receiving this error:

Neo.ClientError.Statement.ExternalResourceFailed

Any help would be greatly appreciated :)

2 Answers

SOLUTIONS:

This is a security feature that is auto-enabled in neo4j 3.0 and above. It disallows files to be loaded from anywhere in the filesystem.

You have 2 Solutions/Options:

  1. Leave the setting as is and simply place all CSV files to be read in the "import" directory(folder) located in the install directory(folder).
  2. Change the security feature to allow the importation of CSVs from any directory in the filesystem.

OPTION 1:

This option is straight forward, simply copy and paste all CSV files to be read in the "import" directory(folder) located in the install directory(folder).

Then use the path as follows for the file (eg. to load a CSV file "data.csv" which was pasted into the import directory(folder)

LOAD CSV file:///data.csv

OPTION 2:

To allow any url or filepath to be imported, you must navigate to the neo4j.conf file. The file is found in the conf Folder in the install directory. Alternatively, you can simply search for the "neo4j.conf" file.

Upon locating the file open it (using Notepad or other). Then ensure that "dbms.security.allow_csv_import_from_file_urls=true" below is NOT commented out (remove "#") && "dbms.directories.import=import" below is commented out (add "#").

# Determines if Cypher will allow using file URLs when loading data using
# `LOAD CSV`. Setting this value to `false` will cause Neo4j to fail `LOAD CSV`
# clauses that load data from the file system.
dbms.security.allow_csv_import_from_file_urls=true

# This setting constrains all `LOAD CSV` import files to be under the `import` directory. Remove or comment it out to
# allow files to be loaded from anywhere in the filesystem; this introduces possible security problems. See the
# `LOAD CSV` section of the manual for details.
#dbms.directories.import=import
Related