下面我将详细介绍如何在 Nebula Graph 中执行多跳查询(2跳、3跳、4跳等),包括数据准备、常用 MATCH 查询模式和语法详解。
一、扩展测试数据
首先我们扩展测试数据,构建更复杂的图结构:
-- 创建更多Tag和Edge类型
CREATE TAG IF NOT EXISTS skill(name string, level int);
CREATE EDGE IF NOT EXISTS friend(degree string);
CREATE EDGE IF NOT EXISTS learn(years int);-- 插入更多人物顶点
INSERT VERTEX person(name, age) VALUES "p102":("王五", 35),"p103":("赵六", 40),"p104":("钱七", 28),"p105":("孙八", 45);-- 插入更多公司顶点
INSERT VERTEX company(name) VALUES "c202":("字节跳动"),"c203":("美团"),"c204":("拼多多");-- 插入技能顶点
INSERT VERTEX skill(name, level) VALUES "s300":("Java", 3),"s301":("Python", 4),"s302":("Go", 2),"s303":("SQL", 5);-- 添加更多工作关系
INSERT EDGE works(start_date, end_date) VALUES "p102"->"c202":("2017-03-01", ""),"p103"->"c203":("2016-07-01", "2021-05-31"),"p104"->"c204":("2019-09-01", ""),"p105"->"c200":("2010-01-01", "2018-12-31");-- 添加朋友关系
INSERT EDGE friend(degree) VALUES "p100"->"p101":("close"),"p100"->"p102":("normal"),"p101"->"p103":("close"),"p102"->"p104":("normal"),"p103"->"p105":("close");-- 添加学习技能关系
INSERT EDGE learn(years) VALUES "p100"->"s300":(5),"p101"->"s301":(3),"p102"->"s300":(4),"p103"->"s302":(2),"p104"-