SHOW QUERY,这里有社区用户常用的 nGQL 查询语句

由于 NebulaGraph 的每个版本的子句使用会存在出入,以下语句不代表适用于所有的 NebulaGraph 发行版;此外,由于个别语句对特定场景生效,不代表它具有通用性!

  • 语句 1
    • 场景:统计某个节点下游所有节点的数量
    • 具体语句:match (v:player)-[e*1…]->(v2) where id(v)==“player100” return count(distinct v2)
    • 适用版本:v3.2.0
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/12441
  • 语句 2
    • 场景:统计某个节点下游指定 Tag 下所有节点的数量
    • 具体语句:match (v:player)-[e*1..]->(v2:player) where id(v)=="player100" return count(distinct v2)
    • 适用版本:v3.2.0
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/12441
  • 语句 3
  • 语句 4
  • 语句 5
    • 场景:悬挂边的黑点批量删除 / 可用来删除无 tag 的点
    • 具体语句:已知边类型且创建边索引的情况下,先执行 (((lookup on like yield like._src as srcId |go from $-.srcId over like yield id($$) as vid) minus (lookup on like yield like._src as srcId | go from $-.srcId over like yield id($$) as dstId | fetch prop on * $-.dstId yield id(vertex) as vid)) | go from $-.vid over * bidirect yield distinct id($^) as srcId, id($$) as dstId) | delete edge like $-.srcId->$-.dstId 再执行 (((lookup on like yield like._src as srcId |go from $-.srcId over like yield id($$) as vid) minus (lookup on like yield like._src as srcId | go from $-.srcId over like yield id($$) as dstId | fetch prop on * $-.dstId yield id(vertex) as vid)) | go from $-.vid over * bidirect yield distinct id($^) as srcId, id($$) as dstId) | delete edge like $-.dstId->$-.srcId
    • 适用版本:v3.0.2
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/11905/4
  • 语句 6
    • 场景:子图对节点/边的类型或属性过滤
    • 具体语句:get subgraph 2 steps from "Tim Duncan" both serve yield vertices as a | unwind $-.a as t | yield $-.t where "player" in tags($-.t)
    • 适用版本:v3.4.0
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/12108/5
  • 语句 7
    • 场景:统计图中每一个节点的二度出度值
    • 具体语句 1:第一种方式:MATCH (v:A) RETURN size((v)-->()) AS out_degree1, size((v)-->()-->()) AS out_degree2
    • 具体语句 2:第二种方式:MATCH (v:A) WHERE size((v)-->()-->()) > size((v)-->()) RETURN v
    • 适用版本:v3.3.0
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/12067/5
  • 语句 8
    • 场景:输出结果为边列表时,返回边类型属性
    • 具体语句:match (v:player{name:“Tim Duncan”})-[e*1…2]->(v2) unwind e as edgelist return edgelist
    • 适用版本:v3.3.0
    • 语句出处:https://discuss.nebula-graph.com.cn/t/topic/12028
2 个赞