Cypher Neo4j Couldn't load the external resource

前端 未结 15 1719
谎友^
谎友^ 2021-02-07 05:09

In a Windows environment, I\'m trying to load a .csv file with statement:

LOAD CSV WITH HEADERS FROM \"file:///E:/Neo4j/customers.csv\" AS row

相关标签:
15条回答
  • 2021-02-07 05:36

    The easiest way (be ware of security) is to serve you directory over http and use the http import

    • in the command line go the folder where csv files are lcoated
    • run the following depending on your python env.

    Python 2 $ python -m SimpleHTTPServer 8000 Python 3 $ python3 -m http.server 8000 - Now you can load your files from your local host LOAD CSV FROM 'http://localhost:8000/mycsvfile.csv' AS row return row - you can actually expose files on one host and load them where your DB is running by exposing the folder and replacing localhost with your IP

    0 讨论(0)
  • 2021-02-07 05:38

    Neo4j version is 3.1.1, OS is win10.

    For me, LOAD CSV would read from Neo4j_Database_Location/testDB/import/artists.csv.

    At first, I put csv file on the path F:\code\java\helloworld\artists.csv, and my cypher sentence is

    LOAD CSV FROM 'file:///F:\\code\\java\\helloworld\\artists.csv' AS line  
    CREATE(:Artist {name:line[1],year:toInt(line[2])})
    

    Then I get the error message returned as follows:

    Couldn't load the external resource at: file:/D:/Neo4j/db/testDB/import/code/java/helloworld/artists.csv
    

    It means neo4j itself concat the file path. "D:/Neo4j/db/testDB/import/" is the Neo4j database location, and the "code/java/helloworld/artists.csv" is the csv file location.

    For example, I install Neo4j on the path D:\Neo4j\Neo4j CE 3.1.1, and database loaction is D:\Neo4j\db. I put the CSV file on the path D:\Neo4j\db\testDB\import\artist.csv. If you don't have the file folder "import" on the path, you should creat it by yourself and put your file in the folder "import".

    Then, put your csv file in the path, and input cyper sentence:

    LOAD CSV from 'file:///artist.csv' as LINE
    CREATE(:Artist {name:line[1],year:toInt(line[2])})
    

    In a word, once you put the CSV file in the right path, the problem can be solved.

    Related explaination in the LOAD CSV developer-manal

    If dbms.directories.import is set to the default value import, using the above URLs in LOAD CSV would read from /import/myfile.csv and import/myproject/myfile.csv respectively. If it is set to /data/csv, using the above URLs in LOAD CSV would read from /data/csv/myfile.csv and /data/csv/myproject/myfile.csv respectively.

    0 讨论(0)
  • 2021-02-07 05:41

    On (Arch) Linux + neo4j-community-3.4.0-alpha09, edit $NEO4J_HOME/conf /neo4j.conf:

    • uncomment or add: dbms.security.allow_csv_import_from_file_urls=true
    • comment: #dbms.directories.import=import

    Restart neo4j (in terminal: neo4j restart), and reload the Neo4j Browser (http://localhost:7474/browser/) if you are using a web browser as your Neo4j interface/GUI.

    Then, you should be able to load a csv from outside your $NEO4J_HOME/... directory

    E.g.,

    LOAD CSV WITH HEADERS FROM "file:///mnt/Vancouver/Programming/data/metabolism/practice/a.csv" AS ...

    where my $NEO4J_HOME/ is /mnt/Vancouver/apps/neo4j/neo4j-community-3.4.0-alpha09/

    LOAD CSV WITH HEADERS FROM "file:/mnt/Vancouver/Programming/data/metabolism/practice/a.csv" AS ...

    also works, but not

    LOAD CSV WITH HEADERS FROM "file://mnt/Vancouver/Programming/data/metabolism/practice/a.csv" AS...

    or

    LOAD CSV WITH HEADERS FROM "/mnt/Vancouver/Programming/data/metabolism/practice/a.csv" AS...

    i.e. use ...file:/... or ...file:///...

    0 讨论(0)
  • 2021-02-07 05:41

    I am using the Neo4j Desktop and as others have said, the default graph database has a predefined import location. You can find the location by using the UI. If you put the CSV into the import directory, then you can use the relative path directly from you load csv command

    0 讨论(0)
  • 2021-02-07 05:42

    Add your csv file in the import folder of neo4j installation guide to do this.

    1. open neo4j and start graph of ur project

    2. then in open folders tab open import folders

    3. Copy ur csv file in this folder

    4. Copy that part in ur load syntax as file:///C:/neo4j_module_datasets/test.csv since ur neo4j in running in C drive

    Snapshot for your reference

    0 讨论(0)
  • 2021-02-07 05:43

    Use the following syntax:

    LOAD CSV WITH HEADERS FROM "file:///my_collection.csv" AS row CREATE (n:myCollection) SET n = row
    

    If you are running a docker then, follow these commands before running above query:

    docker run \
    -p=7474:7474 \
    -p=7687:7687 \
    -v=$HOME/neo4j/data:/data \
    -v=$HOME/neo4j/logs:/logs \
    -v=$HOME/local_import_dir:/var/lib/neo4j/import \
    neo4j:3.0
    

    Then,

    sudo cp my_collection.csv /home/bajju/local_import_dir/
    
    0 讨论(0)
提交回复
热议问题