neo4j:如何返回带有节点和关系标签的路径?

时间:2018-01-11 15:49:27

标签: neo4j cypher graph-databases

我的查询返回路径:

match path = ...
return path

但缺少节点和关系标签。我该如何添加它们?

return path, labels(path)

给出错误

2 个答案:

答案 0 :(得分:0)

您可以在整个路径中使用命名节点。然后对每个命名节点(labels(a) + labels(b))的标签求和。之后,您可以使用UNWINDcollect 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

答案 1 :(得分:0)

我设法实现的最好的事情是

match path = ...
return path, extract (x in rels(path) | type(x)) as types, extract (n in nodes(path) | labels(n)) as labels

它允许人们重建后端的整个路径结构。虽然仍然包含很多重复