Gremlin 在 n 层上找到所有连接的顶点
Gremlin find all connected Vertices over n levels
我基本上是在尝试搜索节点类型的所有连接顶点,Cypher 查询版本给出了预期的结果,但 Gremlin 版本没有给出预期的结果。我做错了什么吗??
Visual Representation of my data
Cyher Query to fetch all the connections
MATCH p=shortestPath((n:Process)-[*]-(m:Process))
WHERE n <> m
RETURN ID(n), n, ID(m), m, length(p)
Gremlin version
gremlin> g.V().hasLabel('Process')
.repeat(both().simplePath())
.until(hasLabel('Process'))
.path().by('title')
==>[Cash Processing,Accounting]
==>[Cash Processing,Sales]
==>[Sales,Marketing]
==>[Sales,Cash Processing]
==>[Marketing,Accounting]
==>[Marketing,Sales]
==>[Accounting,Cash Processing]
==>[Accounting,Marketing]
知道为什么 Gremlin 没有捕捉到 'Cash Processing'->'Sales'->'Marketing' 连接吗???
我觉得 until() 函数需要更改,但不知道是什么
你没有谈论顶点的标签,但对我来说,Sales
顶点似乎已经满足 until(HasLabel('Process'))
停止条件。
你的 Cypher 查询的正确翻译应该是这样的:
g.V().hasLabel('Process').as('n').
repeat(both().simplePath()).
emit(hasLabel('Process')).as('m').
dedup('n','m').
path().count(local).as('len').
select('m','n','len')
我基本上是在尝试搜索节点类型的所有连接顶点,Cypher 查询版本给出了预期的结果,但 Gremlin 版本没有给出预期的结果。我做错了什么吗??
Visual Representation of my data
Cyher Query to fetch all the connections
MATCH p=shortestPath((n:Process)-[*]-(m:Process))
WHERE n <> m
RETURN ID(n), n, ID(m), m, length(p)
Gremlin version
gremlin> g.V().hasLabel('Process')
.repeat(both().simplePath())
.until(hasLabel('Process'))
.path().by('title')
==>[Cash Processing,Accounting]
==>[Cash Processing,Sales]
==>[Sales,Marketing]
==>[Sales,Cash Processing]
==>[Marketing,Accounting]
==>[Marketing,Sales]
==>[Accounting,Cash Processing]
==>[Accounting,Marketing]
知道为什么 Gremlin 没有捕捉到 'Cash Processing'->'Sales'->'Marketing' 连接吗???
我觉得 until() 函数需要更改,但不知道是什么
你没有谈论顶点的标签,但对我来说,Sales
顶点似乎已经满足 until(HasLabel('Process'))
停止条件。
你的 Cypher 查询的正确翻译应该是这样的:
g.V().hasLabel('Process').as('n').
repeat(both().simplePath()).
emit(hasLabel('Process')).as('m').
dedup('n','m').
path().count(local).as('len').
select('m','n','len')