Neo4j-数据导入

fansichao 2021-10-23 16:25:17
Categories: > Tags:

数据导入

数据导入的几种方式

参考链接:

本节主要说明三种导入方式 loadcsv、neo4j-import、batch-import

本文数据导入使用唯一 ID(node)

数据导入的注意事项

Neo4j-import

注意事项

文件格式

文件格式样例

1
2
3
4
# cust.csv
id:ID,certno,name,label,cust_certtype:string,cust_namespell:string,birthday:int,sex:string,address:string,mob_phone:string
# tran.csv
:START_ID,:END_ID,Type,tran_date:int,amount:int,count:int

文件格式说明

导入命令

1
2
3
4
5
6
7
8
9
10
11
12
13
neo4j-import适应场景
neo4j-import参数 (bin/neo4j-import help)
- 指定最大进程数 --processors <max processor count>
- 跳过重复节点 --skip-duplicate-nodes <true/false>
- 跳过异常关系 --skip-bad-relationships <true/false>
- 最大跳过数量 --bad-tolerance <max number of bad entries, or true for unlimited>
- 跳过异常行(例如行列数异常) --ignore-extra-columns <true/false>


命令样例:

bin/neo4j-import --bad-tolerance=1000000 --skip-duplicate-nodes=true --skip-bad-relationships=true --into data/databases/graph.db --id-type string --nodes:cust import/c.csv --relationships:tran import/t.csv

batch-import

注意事项:

文件格式

1
2
3
4
5
6
# cust.csv
id:string:id_index,certno:string:id_index,name,Label:label,cust_certtype:string,cust_namespell:string,birthday:int,sex:string,address:string,mob_phone:string
874018718864465,874018718864465,鞠瑜,cust,其他证件,juyu,19801010,男,河北省岩市龙潭东莞街d座 188848,15767524738
# tran.csv
id:string:id_index,certno:string:id_index,Type,tran_date:int,amount:int,count:int
874018718864465,411224195908138440,tran,20180108,20,2

文件格式说明:

导入命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# batch-import命令
sh import.sh /home/fdm/neo4j_test/neo4j-community-3.0.4/data/databases/fdm.db /home/fdm/import_data/c.csv /home/fdm/import_data/t.csv

# batch-import3.0已经编译好的软件包
https://github.com/mo9527/batch-import-tool

# batch.properties配置文件
dump_configuration=false
cache_type=none
use_memory_mapped_buffers=true
neostore.propertystore.db.index.keys.mapped_memory=1000M
neostore.propertystore.db.index.mapped_memory=10M
neostore.nodestore.db.mapped_memory=10240M
neostore.relationshipstore.db.mapped_memory=10240M
neostore.propertystore.db.mapped_memory=5120M
neostore.propertystore.db.strings.mapped_memory=2000M
#batch_import.csv.quotes=true
#batch_import.csv.delim=,workInfoId
#contactRecordId deviceId workInfoId
#batch_array_separator=,

batch_import.csv.quotes=true
batch_import.csv.delim=,
batch_import.keep_db=true
batch_import.node_index.id_index=exact
batch_import.node_index.id_index2=exact
batch_import.node_index.id_index3=exact

Load-csv

文件格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
load csv 导入格式要求

# cust.csv
id,certno,name,label,cust_certtype,cust_namespell,birthday,sex,address,mob_phone
# tran.csv
start_id,end_id,type,tran_date,amount,count

# create 节点
LOAD CSV WITH HEADERS FROM "file:///cust.csv" AS line create
(p:cust{id:line.id,certno:line.certno,name:line.name,label:line.label,cust_certtype:line.cust_certtype,cust_namespell:line.cust_namespell,birthday:toInteger(line.birthday),sex:line.sex,address:line.address,mob_phone:line.mob_phone})

# 创建索引
CREATE INDEX ON :cust(id)

# create 边
LOAD CSV WITH HEADERS FROM "file:///tran.csv" AS line match
(from:cust{id:line.start_id}),(to:cust{id:line.end_id}) create (from)-[r:tran{ type:line. type,tran_date:line.tran_date,amount:line.amount,count:line.count}]->(to)

其他说明

特殊说明

csv 数据导入失败:可能性有多种

文件 head 头不对。 存在节点和交易关系头不对的情况

节点或交易边数据,ID 存在重复。 csv 文件中 ID 必须唯一。且所有实体表中的:ID 是必须写的,并且 ID 全局唯一,也就是三个表格中的 ID 都是唯一的,不可以有重复,在关系表中,不可以存在没有 ID 指向的实体。

参考资源

性能测试

neo4j-import 方式

IMPORT DONE in 1m 17s 799ms. Imported:
7295460 nodes
10000000 relationships
112954600 properties

real 1m19.456s
user 5m51.375s
sys 0m15.706s

耗时 79.73S 速度 216,916.30 条/s