本文介绍如何将数据从Neo4j数据库导入嬴图数据库。

以下步骤均在Windows系统上PowerShell中演示。
生成配置文件
打开终端程序,导航至ultipa-importer
所在文件夹。执行以下命令,选择neo4j
,为导入Neo4j数据库中的数据生成样本配置文件:
./ultipa-importer --sample

执行命令后,会在ultipa-importer
所在目录下生成配置文件import.sample.neo4j.yml
。如果目录下已有该文件,数据将被覆盖。
修改配置文件
根据实际使用场景修改import.sample.neo4j.yml
文件。该文件包含以下部分:
mode
:设置为neo4j
。neo4j
:配置Neo4j数据库连接。server
:提供嬴图服务器信息,并为数据导入指定目标图(新图或已有图)。nodeConfig
:定义点schema,其中每个schema对应一个标签。查询结果中的各列将映射为点属性。edgeConfig
:定义边schema,其中每个schema对应一个关系。查询结果中的各列将映射为边属性。settings
:为数据导入设置全局参数和偏好。
# 导入模式:csv/json/jsonl/rdf/graphml/bigQuery/sql/kafka/neo4j/salesforce
mode: neo4j
# Neo4j服务器配置
neo4j:
# 主机IP/URI,"neo4j://xxx:" or "neo4j+s://xxx"
host: "neo4j+s://123xxx.databases.neo4j.io"
username: "user123"
password: "password123"
# 数据库名称
database: "trading"
# 嬴图服务器配置
server:
# 主机IP/URI和端口;若为集群,使用英文逗号分隔
host: "10.11.22.33:1234"
username: "admin"
password: "admin12345"
# 目标图(新图或已有图)
graphset: "myGraph"
# 若上图为新图,指定图所在分片
shards: "1,2,3"
# 若上图为新图,指定分片分区算法(Crc32/Crc64WE/Crc64XZ/CityHash64)
partitionBy: "Crc32"
# TLS加密证书文件路径
crt: ""
# 点配置
nodeConfig:
# 指定schema
- schema: "Customer"
# 指定Neo4j中的标签
label: "customer"
# 设置查询条件(如需),使用变量n查询标签
where: n.level > 0
# 设置返回记录数(如需)
limit:
# properties: 将查询结果中的各列映射为属性;映射为系统属性_id、_from或_to的各列必须明确设置
## name: Neo4j数据库中的字段名,用作嬴图数据库中的属性名;若需使用Neo4j的identity、start或end属性,将该字段设置为<id>、<start>或<end>
## new_name: 嬴图数据库中的属性名;默认为上述名称
## type: 属性类型;可设置为 _id,_from,_to或其他嬴图属性,如int64,float,string登;设置为 _ignore时可跳过导入该列
## prefix: 为属性值增加前缀;仅适用于_id,_from和_to
properties:
- name: <id>
type: _id
- name: cust_no
type: string
- name: name
type: string
- name: level
type: int32
- schema: "Merchant"
label: "merchant"
properties:
- name : <id>
type: _id
# 边配置
edgeConfig:
- schema: "Transfers"
# 指定Neo4j中的关系
relationship: "transfers"
# 设置查询条件(如需),使用变量r查询关系
where:
properties:
- name: <start>
type: _from
- name: <end>
type: _to
- name: trans_no
type: string
- name: time
type: datetime
# 全局设置
settings:
# 日志文件路径
logPath: "./logs"
# 每批次导入的点或边的数量
batchSize: 10000
# 插入模式:insert/overwrite/upsert
importMode: insert
# 插入边时,自动创建缺失端点
createNodeIfNotExist: false
# 报错时停止数据导入
stopWhenError: false
# 设置为true时,自动创建新的图、schema和属性
yes: true
# 最大线程数
threads: 32
# RPC最大消息传输量(单位:MB)
maxPacketSize: 40
# 时间戳对应时区
# 默认时区:"+0200"
# 时间戳单位,支持毫秒(ms)或秒(s)
timestampUnit: s
执行导入
使用--config
标志指定配置文件,执行数据导入:
./ultipa-importer --config import.sample.neo4j.yml
