我已经看了关于这个主题的所有其他问题,所有的答案(即使是批准的答案)要么不完整,要么是错误的。因此,我提供了一些具体的例子,希望能得到一个明确的解释。
我在neo4j.conf中尝试了以下设置,所有设置似乎都以相同的方式处理:
dbms.directories.import=d:\import\
dbms.directories.import=d:/import/
dbms.directories.import=d:/import
在浏览器交互会话中使用以下命令,结果在命令的每个版本上方的注释中
// URI is not hierarchical
LOAD CSV WITH HEADERS FROM "file:Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
// Invalid input '/', makes sense but violates "correct" syntax seen online
LOAD CSV WITH HEADERS FROM file:/d:Endpoint.csv AS row WITH row LIMIT 4 RETURN row
LOAD CSV WITH HEADERS FROM file://d:/import/Endpoint.csv AS row WITH row LIMIT 4 RETURN row
LOAD CSV WITH HEADERS FROM file:///d:/import/Endpoint.csv AS row WITH row LIMIT 4 RETURN row
// works, but the drive letter used is completely ignored
LOAD CSV WITH HEADERS FROM "file:/d:Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
// works
LOAD CSV WITH HEADERS FROM "file:/Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
LOAD CSV WITH HEADERS FROM "file:///Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
// Cannot load from URL 'file://Endpoint.csv': file URL may not contain an authority section (i.e. it should be 'file:///')
LOAD CSV WITH HEADERS FROM "file://Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
// URI is not hierarchical
LOAD CSV WITH HEADERS FROM "file:d:/import/Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
LOAD CSV WITH HEADERS FROM "file:d:\import\Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
// Couldn't load the external resource at: file:/d:/import/import/Endpoint.csv
LOAD CSV WITH HEADERS FROM "file:///d:/import/Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
LOAD CSV WITH HEADERS FROM "file:///d:\import\Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
这应该有效:
dbms.directories.import=d:/import
LOAD CSV WITH HEADERS FROM "file:///Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
它将查找与配置的导入目录相关的文件。
如果删除(注释掉)config选项,也可以提供绝对路径。
LOAD CSV WITH HEADERS FROM "file:///d:/import/Endpoint.csv" AS row WITH row LIMIT 4 RETURN row
所有文件URI都是相对于dbms.directories.import
中提供的路径解析的。因此,根据您的设置,file:///Endpoint.csv
是加载D:importEndpoint.csv
的"最正确"方式。
我们将LOAD CSV限制在指定路径下的相对路径的原因是为了防止Cypher访问任意文件系统。
/
和///
都能工作的原因是"文件URL没有权限段",因此它可以被提交。(参见此答案。)
如果您的"数据库位置"是:C:\path1\Neo4jMyData\
(启动C:\programs_path\neo4j ce.exe后设置)
1.目录C:\path1\Neo4jMyData\import\必须存在
2.复制C:\path2……\people_LOCAL.csv C:\path1\Neo4jMyData\import\
3.在浏览器中的Neo4J控制台社区版:
从加载CSV"file:///people_LOCAL.csv"AS行
CREATE(:Person{userId:toInt(row[0]),name:row[1]})
4.这对我来说是工作(在Windows下)13-10-2016 10:55
---这是您测试的"people_LOCAL.csv"。---
1,"John"
10,"Jane"
234,"Fred"
4893,"Mark"
234943,"Anne"