1
我试图通过id搜索特定的节点,然后返回距该节点1或2跳的所有节点和关系。我也试图将结果格式化为用于D3的JSON。感谢来自@ william-lyon以前的帖子的一些帮助,我设法让查询工作1跳。我现在的问题是,当我将它扩展到2跳时,当我想要只有不同的节点和关系时,我会得到重复项。我试图使用RETURN(DISTINCT X)函数,但我无法使它工作。从cypher返回不同的节点和关系,格式为JSON
MATCH (l0) -[r1]-> (l1) -[r2]-> (l2)
WHERE ID(l0) = 65
RETURN
[
{
type: "node",
id: id(l0),
labels: labels(l0),
props: apoc.map.fromPairs([key IN keys(l0) | [key, l0[key]]])
},
{
type: "node",
id: id(l1),
labels: labels(l1),
props: apoc.map.fromPairs([key IN keys(l1) | [key, l1[key]]])
},
{
type: "node",
id: id(l2),
labels: labels(l2),
props: apoc.map.fromPairs([key IN keys(l2) | [key, l2[key]]])
}
] as nodes,
[
{
startNodeId: ID(startNode(r1)),
endNodeId: ID(endNode(r1)),
relType: type(r1)
},
{
startNodeId: ID(startNode(r2)),
endNodeId: ID(endNode(r2)),
relType: type(r2)
}
] as relationships
非常感谢
这很好用 - 非常感谢!我已经放弃了试图让这个工作,我开始尝试使用apoc.convert.toTree“程序,但是你的解决方案是完美的,我感谢你的帮助。 – n4nite