具体语句:已知边类型且创建边索引的情况下,先执行 (((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
// 1
MATCH(v)-[e:person_knows_person*1..3]-(v2) WHERE v.person.firstName == "firstName"
// 2
OPTIONAL MATCH (v2)-[e2: person_isLocatedIn_place]-(v3)
// 3
OPTIONAL MATCH (v2)-[e3: person_studyAt_organisation]-(v4)
// 4
OPTIONAL MATCH (v2)-[e3: person_workAt_organisation]-(v5)
// 查找国家
...
WITH v2 as personName, v3 as workingPlace, v4 as college, v5 as company
RETURN personName, workingPlace, college, company, country
具体语句:以统计某条边为例子,记得 MATCH 需要创建索引,如果是导入数据后创建的索引,记得进行 REBUILD INDEX 操作。
# LOOKUP
lookup on edge_name yield edge as e | yield count(*)
# MATCH
match (m) - [e:edge_name] - (n) return count(e)
# SHOW STATS
看文档:https://docs.nebula-graph.com.cn/3.4.1/3.ngql-guide/7.general-query-statements/6.show/14.show-stats/
lookup on player yield id(vertex) as vid
minus
(lookup on player yield id(vertex) as vid | go 1 step from $-.vid over * bidirect yield distinct id($^) as vid)
)
| delete vertex $-.vid
get subgraph 5 step from pod in have,belong yield vertices as nodes, edges as relationshiops
union all
get subgraph 5 step from pod out have,belong yield vertices as nodes, edges as relationshiops
MATCH (a)-[b]->(c) where id(a)="*****"
WITH labels(c) AS ctype, collect(distinct c)[0..10] AS c_with_same_type
UNWIND c_with_same_type AS cc
OPTIONAL MATCH (cc)-[d]->(e)
RETURN cc, d, e
LOOKUP ON ip YIELD id(vertex) as id
| GO FROM $-.id over activeIn REVERSELY
WHERE head(labels($)) == 'equipment'
YIELD id($) as dst, id($^) as src
| GO FROM $-.dst over login REVERSELY
WHERE head(labels($)) == 'account'
YIELD id($) as dst, id($^) as src
|GROUP BY $-.src YIELD $-.src as src,count($-.src) as degree
| YIELD $-.src as src where $-.degree > $p0
| GO FROM $-.src over login REVERSELY
YIELD properties($).accountUuid as accountUuid
match (v1:player)-[e:serve]->(v2:team)
with max(rank(e)) as max_rank
match (v3:player)-[e2:serve]->(v4:team)
where rank(e2) == max_rank
return count(e2);
MATCH p=(v)-[*1..10]-(m)
where id(v)=="host001" and all( midNode in [n in nodes(p) where id(n)<>id(v) | n] where "frontPort" not in tags(midNode))
RETURN p
((lookup on table | yield $-.VertexID as id)
MINUS
(lookup on table | yield $-.VertexID as id | go from $-.id over * BIDIRECT yield $-.id as id))
| delete $-.id
match (v) with properties(v) as props, keys(properties(v)) as kk, v limit 10000 where [i in kk where props[i] == “Tony Parker”] return v
match ()-[e]->() with e, properties(e) as props, keys(properties(e)) as kk limit 10000 where [i in kk where props[i] == 90] return e
#GO
GET SUBGRAPH 10 steps FROM "Tim Duncan" IN EdgeType YIELD VERTICES AS nodes | yield $-.nodes[6]
#MATCH
MATCH (v)<-[:EdgeType*1..10]-(n)
WHERE id(v)=="vid" AND NOT (n)<-[:EdgeType]-()
RETURN n
GO 3 STEPS FROM "ADDRESS_1015" OVER related YIELD
case when $^.Staff.STAFF_NAME IS NOT EMPTY and $^.Staff.STAFF_ROLE == "派送人员" then related._src else null end AS dst,
case when $.busi_store.BUSI_STORE_NAME IS NOT EMPTY then properties($) else null end AS props;
GO FROM "Tim Duncan" OVER like YIELD like._dst AS dst | FETCH PROP ON * $-.dst YIELD player.age AS age,vertex AS allProperties | ORDER BY $-.age | LIMIT 3 | YIELD $-.allProperties AS allProperties
(root@nebula) [nba]> """
-> match (v:player) where v.player.age>43
-> match (n:team) where n.team.name starts with "S"
-> with v,n,(v)-->(n) as l
-> return v.player.name,n.team.name,case when size(l)<>0 then true else false end AS hasConnection
-> """
GO FROM <A>/* 这里需要是id */ over com WHERE $^.acc.time >= "" yield e1._dst AS dst, $^.acc.flgid AS flgid
| GO FROM $-.dst OVER com REVERSELY WHERE $^.acc.time >= "" AND $^.acc.timeflg==0 AND $-.flgid=$.comtag.flgid /*其他过滤属性同理*/ YIELD $-.src AS A, com._src AS B
UNION
MATCH (v)--(v2) WHERE id(v2)=="player100" RETURN DISTINCT id(v)
INTERSECT MATCH (v)--(v2) WHERE id(v2)=="team203" RETURN DISTINCT id(v)
INTERSECT MATCH (v)--(v2) WHERE id(v2)=="player101" RETURN DISTINCT id(v)
FIND ALL PATH WITH PROP FROM "player100" TO "player101" OVER follow BIDIRECT
YIELD path AS p |
YIELD $-.p, reduce(total_weight = 0, r IN relationships($-.p) | total_weight + r.degree) AS total_weight |
ORDER BY $-.total_weight DESC
Get Subgraph with prop N steps From 'xxx' OUT edgeType WHERE $$.person.is_skip is EMPTY OR $$.person.is_skip == false YIELD vertices AS nodes, edges AS relationships
MATCH (uu:player)-[e:follow]->(p:player)-[:serve]->(f:team)
WHERE id(f) == "team204"
WITH p
MATCH ()-[e:follow]->(p:player)
WITH id(p) AS p, e.degree AS degree, count(e) AS count
RETURN p, collect(degree), collect(count)