neo4j:如何 return 带有节点和关系标签的路径?
neo4j: how to return paths with labels of nodes and relations?
我的查询 returns 路径:
match path = ...
return path
但缺少节点和关系标签。我怎样才能添加它们?
return path, labels(path)
报错
您可以在整个路径中使用命名节点。然后对每个命名节点 (labels(a) + labels(b)
) 的标签求和。在它之后,您可以使用 UNWIND
和 collect distinct
删除重复项。此外,您可以执行相同的操作来获取关系类型,但使用 relationships() 函数。
match path = (a)-->(b)
with path, labels(a) + labels(b) as labels, relationships(path) as relationships
unwind(labels) as label
unwind(relationships) as relationship
return path, collect(distinct label) as labels, collect(distinct type(relationship)) as relationships
我取得的最好成绩是
match path = ...
return path, extract (x in rels(path) | type(x)) as types, extract (n in nodes(path) | labels(n)) as labels
它允许在后端重建整个路径结构。虽然仍然包含很多重复
我的查询 returns 路径:
match path = ...
return path
但缺少节点和关系标签。我怎样才能添加它们?
return path, labels(path)
报错
您可以在整个路径中使用命名节点。然后对每个命名节点 (labels(a) + labels(b)
) 的标签求和。在它之后,您可以使用 UNWIND
和 collect distinct
删除重复项。此外,您可以执行相同的操作来获取关系类型,但使用 relationships() 函数。
match path = (a)-->(b)
with path, labels(a) + labels(b) as labels, relationships(path) as relationships
unwind(labels) as label
unwind(relationships) as relationship
return path, collect(distinct label) as labels, collect(distinct type(relationship)) as relationships
我取得的最好成绩是
match path = ...
return path, extract (x in rels(path) | type(x)) as types, extract (n in nodes(path) | labels(n)) as labels
它允许在后端重建整个路径结构。虽然仍然包含很多重复