neo4j导入数据

Posted Circle-C

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了neo4j导入数据相关的知识,希望对你有一定的参考价值。

1.从网络文件导入

# 导入节点
WITH "https://github.com/neo4j-graph-analytices/book/raw/master/data" AS base 
WITH base + "transport-nodes.csv" AS uri
LOAD CSV WITH HEADERS FROM uri AS row
MERGE (place:Place id:row.id)
SET place.latitude = toFloat(row.latitude),
    place.longitude = toFloat(row.longitude),
    place.population = toInteger(row.population)
# 导入关系
WITH "https://github.com/neo4j-graph-analytices/book/raw/master/data" AS base 
WITH base + "transport-relationships.csv" AS uri
LOAD CSV WITH HEADERS FROM uri AS row
MATCH (origin:Placeid:row.src)
MATCH (destination:Placeid:row.dst)
MERGE (origin)-[:EROAD distance: toInteger(row.cost)]->(destination)

2.从本地csv文件导入

Github国内可能无法访问,可以将文件下载到本地,再复制到neo4j安装目录的import文件夹

数据地址:book/data at master · neo4j-graph-analytics/book · GitHub

 

 在console中导入数据:

注意:文件路径是file:///xxx 

# 导入节点
LOAD CSV WITH HEADERS  FROM "file:///transport-nodes.csv" AS line
MERGE (place:Placeid:line.id)
# 导入关系
LOAD CSV WITH HEADERS  FROM "file:///transport-relationships.csv" AS line
MATCH (origin:Placeid:line.src)
MATCH (destination:Placeid:line.dst)
MERGE (origin)-[:EROAD distance: toInteger(line.cost)]->(destination)

点击console右边关系“EROAL”即可查看导入的数据

 点击节点名称或关系名称,即可调整图形的颜色、线条粗细、显示的属性值等

 

以上是关于neo4j导入数据的主要内容,如果未能解决你的问题,请参考以下文章

neo4j数据库迁移---------Neo4j数据库导入导出的方法

知识图谱Neo4j 数据导入与数据库切换

Neo4j数据导入

2021/8/29Windows下Neo4j批量导入数据(最新教程)

如何将数据从sql导入neo4j

Neo4j导入数据的三种方式