https://docs.nebula-graph.com.cn/3.0.1/3.ngql-guide/7.general-query-statements/2.match/
CREATE TAG player (name string, age int);
INSERT VERTEX actor(name, age) VALUES "1":("Tim Duncan", 39);
INSERT VERTEX actor(name, age) VALUES "2":("hehe", 32);
INSERT VERTEX actor(name, age) VALUES "3":("haohao", 32);
UPDATE VERTEX ON player "2" SET name = "two"
UPDATE VERTEX ON player "3" SET name = "three"
CREATE TAG INDEX IF NOT EXISTS name ON player(name(20));
CREATE EDGE INDEX IF NOT EXISTS follow_index on follow();
CREATE TAG actor (name string, age int);
INSERT VERTEX actor(name, age) VALUES "player100":("Tim Duncan", 42);
CREATE EDGE IF NOT EXISTS e1();
CREATE EDGE IF NOT EXISTS e2 (name string, age int);
INSERT EDGE e2 (name, age) VALUES "1"->"2":("n1", 12);
INSERT EDGE e2 (name, age) VALUES "3"->"2":("n3", 32);
INSERT EDGE e1 () VALUES "1"->"3":();
INSERT EDGE e1 () VALUES "2"->"3":();
INSERT EDGE e1 () VALUES "3"->"2":();
# 重建索引使其生效。
REBUILD TAG INDEX name;
REBUILD EDGE INDEX follow_index
匹配 Tag
MATCH (v:player) RETURN v LIMIT 3;
匹配点:
MATCH (v) RETURN v LIMIT 5;
匹配多tag到点:
MATCH (v:player:actor) RETURN v LIMIT 10;
匹配点的属性
match (v:player{name:"hehe"}) return v
MATCH (v:player) WHERE v.player.name == "Tim Duncan" RETURN v;
MATCH (v) WHERE id(v) == 'player100' RETURN v;
点点查找;
match(v:player{name:"hehe"})--(v2) where id(v2) in ["1","2"] return v2;
match (v) return v limit 10
MATCH (v:player{name:"Tim Duncan"})--(v2:player) RETURN v2
用户可以在--符号上增加<或>符号指定边的方向
MATCH (v:player{name:"Tim Duncan"})-->(v2:player) RETURN v2.player.name AS Name;
case表达式:
MATCH (v:player{name:"Tim Duncan"})--(v2) \
RETURN \
CASE WHEN v2.team.name IS NOT NULL \
THEN v2.team.name \
WHEN v2.player.name IS NOT NULL \
THEN v2.player.name END AS Name;
MATCH (v:player{name:"Tim Duncan"})-->(v2)<--(v3) \
RETURN v3.player.name AS Name;
匹配路径
MATCH p=(v:player{name:"Tim Duncan"})-->(v2) RETURN p
匹配边:
MATCH ()<-[e]-() RETURN e LIMIT 3;
匹配边type:
MATCH ()-[e:e1]->() RETURN e imit 3;
MATCH ()-[e:e2]->() RETURN e imit 3;
匹配边属性:
MATCH (v:player{name:"Tim Duncan"})-[e:e2{age:12}]->(v2) RETURN e;
多边type:
MATCH (v:player{name:"Tim Duncan"})-[e:e1|:e2]->(v2) RETURN e;
匹配多边
MATCH (v:player{name:"Tim Duncan"})-[]->(v2)<-[e:e1]-(v3) RETURN v2, v3;
匹配定长路径
MATCH p=(v:player{name:"Tim Duncan"})-[e:e1*2]->(v2) RETURN DISTINCT v2 AS Friends;
如果hop为 0,模式会匹配路径上的起始点
MATCH (v:player{name:"Tim Duncan"}) -[*0]-> (v2) RETURN v2;
匹配变长路径:
MATCH p=(v:player{name:"Tim Duncan"})-[e:e1*1..3]->(v2) RETURN v2 AS Friends;
匹配多个 Edge type 的变长路径:
MATCH p=(v:player{name:"Tim Duncan"})-[e:e1|e2*2]->(v2) RETURN DISTINCT v2;
匹配多模式:
MATCH (v1:player{name:"Tim Duncan"}), (v2:actor{name:"Tim Duncan"}) RETURN v1,v2;
多MATCH检索
MATCH (m)-[]->(n) WHERE id(m)=="2" \
MATCH (n)-[]->(l) WHERE id(n)=="1" \
RETURN id(m),id(n),id(l);
############
option match
MATCH (m)-[]->(n) WHERE id(m)=="1" RETURN id(m),id(n)
MATCH (m)-[]->(n) WHERE id(m)=="1" OPTIONAL MATCH (n)-[]->(l) WHERE id(n)=="2" RETURN id(m),id(n),id(l);
######### lookup
CREATE TAG INDEX IF NOT EXISTS index_player ON player(name(30), age);
REBUILD TAG INDEX index_player;
LOOKUP ON player \
WHERE player.name == "Tim Duncan" \
YIELD id(vertex);
LOOKUP ON player WHERE player.age > 30 IELD id(vertex);
#### 搞挂了 #####
match (v) return v limit 10
LOOKUP ON player \
WHERE player.name STARTS WITH "h" \
YIELD properties(vertex).name, properties(vertex).age;
###########
检索边
CREATE EDGE INDEX IF NOT EXISTS index_e2 ON e2(age);
REBUILD EDGE INDEX index_e2;
show jobs;
LOOKUP ON e2 WHERE e2.age == 12 YIELD edge AS e
LOOKUP ON e2 \
WHERE e2.age > 30 \
YIELD properties(edge).age;
LOOKUP ON e2 \
WHERE e2.age == 12 \
YIELD dst(edge) AS DstVID, properties(edge).age AS age
####### 不好使:
LOOKUP ON e2 \
WHERE e2.age == 12 \
YIELD dst(edge) AS DstVID, properties(edge).age AS age |\
GO FROM $-.DstVID OVER player \
YIELD $-.DstVID, properties(edge).age, properties($$).name;
############## go #########
GO FROM "1" OVER e2 YIELD dst(edge);
两跳的
GO 2 steps FROM "1" OVER e1 YIELD dst(edge);
过滤条件:
GO FROM "1", "2" OVER e2 \
WHERE properties(edge).age > 10 \
YIELD DISTINCT properties($$).name AS team_name, properties(edge).age AS age, properties($^).name AS player_name;
GO FROM "1" OVER e1, e2 YIELD properties(edge).age;
GO FROM "2" OVER e2 REVERSELY \
YIELD src(edge) AS destination;
该 MATCH 查询与上一个 GO 查询具有相同的语义。
MATCH (v)<-[e:e2]- (v2) WHERE id(v) == '2' \
RETURN id(v2) AS destination;
GO FROM "2" OVER e2 REVERSELY \
YIELD src(edge) AS id | \
GO FROM $-.id OVER e2 \
WHERE properties($^).age > 10 \
YIELD properties($^).name AS FriendOf, properties($$).name AS Team;
该 MATCH 查询与上一个 GO 查询具有相同的语义
MATCH (v)-[e:e2]->(v2)<-[e2:e2]-(v3) WHERE id(v) == '1' RETURN v2.player.name AS FriendOf, v3.player.name AS Team;
查询 player100 1~2 跳内的朋友
GO 1 TO 2 STEPS FROM "1" OVER follow \
YIELD dst(edge) AS destination;
GO 1 TO 2 STEPS FROM "1" OVER e2 YIELD dst(edge) AS destination;
GO 1 TO 2 STEPS FROM "1" OVER e1 YIELD dst(edge) AS destination;
该 MATCH 查询与上一个 GO 查询具有相同的语义。
MATCH (v) -[e:e2*1..2]->(v2) WHERE id(v) == "1" RETURN id(v2) AS destination;
根据年龄分组。
GO 1 STEPS FROM "1" OVER e2 \
YIELD src(edge) AS src, dst(edge) AS dst, properties($$).age AS age \
| GROUP BY $-.dst \
YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age
分组并限制输出结果的行数。
GO FROM "1" OVER e2 YIELD src(edge) AS src, dst(edge) AS dst;
$a = GO FROM "1" OVER e2 YIELD src(edge) AS src, dst(edge) AS dst; \
GO FROM $a.dst OVER e1 \
YIELD $a.src AS src, $a.dst, src(edge), dst(edge) \
| ORDER BY $-.src
$a = GO FROM "1" OVER e2 YIELD src(edge) AS src, dst(edge) AS dst; \
GO FROM $a.dst OVER e1 \
YIELD $a.src AS src, $a.dst, src(edge), dst(edge) \
| ORDER BY $-.src | OFFSET 1 LIMIT 2;
############## fetch 语句:
FETCH PROP ON player "1" YIELD properties(vertex);
FETCH PROP ON player "1" YIELD properties(vertex).name AS name;
多tag上的值:
fetch prop on player,actor "1" yield vertex as v;
fetch prop on player,actor "1","2" yield vertex as v;
FETCH语句中使用*获取当前图空间所有标签里,点的属性值
FETCH PROP ON * "1", "2", "3" YIELD vertex AS v
获取边上的值
FETCH PROP ON e2 "1" -> "2" YIELD properties(edge);
FETCH PROP ON e2 "3" -> "2" YIELD properties(edge);
获取边上的指定属性值:
FETCH PROP ON e2 "1" -> "2" \
YIELD properties(edge).age;
获取多条边的属性值:
FETCH PROP ON e2 "1" -> "2", "3" -> "2" YIELD edge AS e;
符合语句:
GO FROM "1" OVER e2 \
YIELD src(edge) AS s, dst(edge) AS d \
| FETCH PROP ON e2 $-.s -> $-.d \
YIELD properties(edge).age;
用户也可以通过自定义变量构建类似的查询。
$var = GO FROM "1" OVER e2 \
YIELD src(edge) AS s, dst(edge) AS d; \
FETCH PROP ON e2 $var.s -> $var.d \
YIELD properties(edge).age;
分享到:
相关推荐
《Nebula Graph Studio 3.8.0 在 ARM 架构下的编译与应用》 在当前数字化时代,图数据库作为一种高效的数据管理工具,正逐渐受到广泛关注。Nebula Graph,作为一款高性能、分布式、易扩展的图数据库,其图形化管理...
Nebula Graph是一款开源的分布式图数据库,其设计目标是提供高效的图数据处理能力,尤其适合大规模图数据的存储和查询。本篇文章将对Nebula Graph的技术概述进行解析,包括其架构设计、代码仓库概览以及代码结构和...
**Jepsen测试框架在图数据库Nebula Graph中的技术实践** Jepsen是一个由Kyle Kingsbury开发的开源测试框架,专门针对分布式数据库、队列和共识系统进行安全性测试。该框架采用Clojure编程语言,旨在发现分布式系统...
【标题】"nebula-graph-studio-v3.1.0" 指的是Nebula Graph的一个前端展示工具的特定版本,版本号为3.1.0。Nebula Graph是一个高性能、分布式、大规模图数据库,适用于处理复杂的关联数据查询和分析。此版本的图形...
Nebula Graph 源码解读系列的第三部分聚焦于 Planner 的实现,这是一个关键组件,负责将经过 Validator 校验的、语义正确的查询语法树转换为可执行的执行计划。执行计划是 Executor 执行查询操作的基础,由一系列...
Nebula Graph是一款高性能、分布式的图数据库,专门设计用于处理大规模复杂数据网络的查询和分析。在V2.6.0版本中,Nebula进一步优化了性能和功能,提升了用户体验,使其在大数据领域的应用更加广泛。 ### 一、...
nebula-graph-3.2.0.el7.x86_64 安装包,包含客户端console
Nebula Graph是一款开源的分布式高性能图数据库,其v2.x版本在2021年3月正式发布。该数据库由吴敏参与开发,他在2019年成为Nebula Graph的产品负责人,并在此前在蚂蚁金服担任图平台的研发工程师,以及在阿里云负责...
星云图(Nebula Graph)是一个开放源代码图数据库,能够托管具有数十亿个顶点(节点)和数万亿条边(具有几毫秒的延迟)的超大规模图。 它提供了企业级的高性能,可以将可以想象得到的最复杂的数据集简化为有意义和...
nebula-graph new
nebula-V3.3.0镜像资源包,包含meta、storged及graphd对应的镜像,以及nebula-console文件
图数据库nebula官方可视化studio的2.0版本docker-compose安装文件
Nebula Operator 是一款专为 Nebula Graph 设计的 Kubernetes 插件,旨在自动化 Nebula Graph 集群在 Kubernetes 上的部署、管理和运维过程。Nebula Graph 是一款高性能的分布式图数据库,其架构包括三个主要服务:...
Nebula Operator 是一个开源的工具,用于在 Kubernetes 集群上自动化部署和管理 Nebula Graph 数据库。Nebula Graph 是一款高性能、分布式、专为大规模图数据处理设计的图数据库。Nebula Operator 提供了一种简单、...
图数据库nebula官方2.0.0版本的rpm安装包
nebula-graph-study nebula-graph-study 数据结构 Vertex 点 保存实体对象的实例 VID 为唯一表示 点必须至少有一个 Tag Tag 标签 用于对点进行区分。相同标签共享相同属性类型 Edge 边 描述 点与点之间的关系行为 一...
**SpringGraph实例详解** SpringGraph是一款图形化工具,主要用于创建和可视化复杂的网络关系图,尤其在数据建模、系统架构设计以及程序流程分析等领域有着广泛的应用。本实例将深入探讨如何利用SpringGraph来构建...