user6854784
user6854784

Reputation:

Unable to load CSV file into Neo4j

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 :)

Upvotes: 3

Views: 4405

Answers (2)

Robert Singh
Robert Singh

Reputation: 71

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

Upvotes: 3

Bruno Peres
Bruno Peres

Reputation: 16355

You should put your CSV file into the import directory of Neo4j installation. For OS X installations this directory is <neo4j-home>/import.

After, your LOAD CSV statement will looks like it:

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

That is: the file URL is relative to the import directory.

Take a look in the Neo4j File Locations docs and Import CSV data guide.

Upvotes: 3

Related Questions