NEO4J入门基础第二章
1、简单导入CSV数据
Load CSV读取但不存入数据库:
查看前CSV文件行数
LOAD CSV FROM "file-url" AS line
RETURN count(*);
复制代码
查看前CSV文件前5行
LOAD CSV FROM "file-url" AS line WITH line
RETURN line
LIMIT 5;
复制代码
1.2 导入CSV时附带表头
LOAD CSV WITH HEADERS FROM "file-url" AS line WITH line
RETURN line
LIMIT 5;
1.3 导入CSV大文件
如果要导入包含大量数据的CSV文件,则可以使用PERODIC COMMIT子句。使用PERODIC COMMIT指示Neo4j在执行完一定行数后提交数据再继续,这样减少了内存开销。使用PERODIC COMMIT默认值为1000行,因此数据将每一千行提交一次。
要使用PERODIC COMMIT,只需在LOAD CSV语句之前插入USING PERIODIC COMMIT语句。
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'http://we-yun.com/neo4jguide/movie.csv' AS line
CREATE(:Movie{title:line.title,released:line.released, tagline:line.tagline})
也可以改变默认单次提交行数,如改为800:
USING PERODIC COMMIT 800
LOAD CSV WITH HEADERS FROM 'http://we-yun.com/neo4jguide/tracks.csv' AS line
CREATE (:Track {TrackId:line.Id, Name:line.Track, Length:line.Length})
使用neo4j-import工具导入到neo4j
bin/neo4j-import --into retail.db --id-type string \ --nodes:Customer customers.csv --nodes products.csv \ --nodes orders_header.csv,orders1.csv,orders2.csv \ --relationships:CONTAINS order_details.csv \ --relationships:ORDERED customer_orders_header.csv,orders1.csv,orders2.csv