官网地址:https://www.nebula-graph.com.cn/
官方文档地址:https://docs.nebula-graph.com.cn/3.8.0/
1.与neo4j对比
Neo4j 更成熟、生态更完善,适合中小规模图数据和快速开发;NebulaGraph 天生分布式,适合十亿级以上节点/边、高并发和需要水平扩展的大规模场景。
主要差异
怎么选
- 优先选 Neo4j:数据量不大、团队想快速验证、需要成熟可视化工具、复杂图查询较多,或者项目依赖丰富的教程和第三方生态。
- 优先选 NebulaGraph:数据量达到亿级甚至十亿级以上、需要高并发实时查询、要在线扩缩容、对国产化/信创有要求,或者希望开源方案支持更大规模集群。
2.部署安装
按官方文档可以快速部署及配置
重启命令
sudo ./nebula.service stop storaged
sudo ./nebula.service start storaged
sudo ./nebula.service stop metad
sudo ./nebula.service start metad
sudo ./nebula.service stop graphd
sudo ./nebula.service start graphd
集群安装时重启后需要
SUBMIT JOB BALANCE LEADER;
3.快速开始
创建space、tag、edge
CREATE SPACE `test` (partition_num = 10, vid_type = FIXED_STRING(256));
--创建tag
CREATE tag `id_num`
(
`roster_type` int DEFAULT 9 COMMENT "黑灰名单标识",
`source` int DEFAULT 9 COMMENT "加黑原因"
);
CREATE tag `phone`
(
`roster_type` int DEFAULT 9 COMMENT "黑灰名单标识",
`source` int DEFAULT 9 COMMENT "加黑原因"
);
--删除tag:DROP TAG `id_num`;DROP TAG `phone`;
--创建edge:
CREATE EDGE phone_with_id_num (weight int, add_time int);
CREATE EDGE id_num_with_phone (weight int, add_time int);
--删除edge:DROP EDGE phone_with_id_num;DROP EDGE id_num_with_phone;
--创建索引
CREATE TAG INDEX idx_id_num_roster_type ON `id_num`(roster_type);
CREATE TAG INDEX idx_id_num ON `id_num`();
CREATE TAG INDEX idx_phone_roster_type ON `phone`(roster_type);
CREATE TAG INDEX idx_phone ON `phone`();
---重建索引
REBUILD TAG INDEX `idx_id_num_roster_type`;
REBUILD TAG INDEX `idx_id_num`;
REBUILD TAG INDEX `idx_phone_roster_type`;
REBUILD TAG INDEX `idx_phone`;
---删除索引 DROP TAG INDEX idx_id_num_roster_type;DROP TAG INDEX idx_id_num;DROP TAG INDEX idx_phone_roster_type;DROP TAG INDEX idx_phone;
添加数据
tag:
INSERT VERTEX id_num(roster_type, source) VALUES "id_num1111":(1,"原因"),"id_num2222":(2,"原因");
INSERT VERTEX phone(roster_type, source) VALUES "phone1111":(1,"原因"),"phone2222":(2,"原因");
DELETE VERTEX "id_num1111";
UPDATE VERTEX ON phone "phone1111" SET roster_type= 3 WHEN roster_type== 1 YIELD roster_type AS rosterType, source AS source; --如果where结果为false,set子句不会生效
UPSERT VERTEX ON phone "phone1111" SET roster_type= 3 WHEN roster_type== 1 YIELD roster_type AS rosterType, source AS source; --如果vid不存在则插入
edge:
INSERT EDGE phone_with_id_num(weight, add_time) VALUES "phone1111"->"id_num1111":(1, 1791475200000), "phone2222"->"id_num2222":(1, 1791475200000);
DELETE EDGE phone_with_id_num "phone1111" -> "id_num1111"@0;
查询支持match和go两种
MATCH (startTag)-[edgeType*1..3]->(endTag) where id(startTag) == 'id_num1111' RETURN startTag,edgeType,endTag limit 5000;
浙公网安备 33010602011771号