[英]Neo4j : return relationship between nodes in a path
As per my schema, I have a "Project" node and multiple "Revision" nodes connected to project. 根据我的架构,我有一个“项目”节点和多个“修订”节点连接到项目。 Every other node is connected to "Revision" nodes applicable. 每个其他节点都连接到适用的“修订”节点。 I need to fetch all nodes that are connected to a particular "Revision" node. 我需要获取连接到特定“修订”节点的所有节点。 While fetching nodes, I need to get the relationship between these nodes too. 在获取节点时,我也需要获取这些节点之间的关系。 I need to restrict the nodes connected to a particular revision. 我需要限制连接到特定修订版的节点。
I tried below query, however, it degrades the performance as DB hits are more while profiling. 我在下面的查询中尝试过,但是,由于性能分析时数据库命中率更高,因此会降低性能。 Every revision will have around 28k nodes and 76k relationships between them. 每个修订版将包含约28k节点以及它们之间的76k关系。
MATCH (a:Project{name:{0}})-[h:HAS_REVISION]->(r:Revision)
WITH a
MATCH p=(a)-[h]->(r)-[*0..2]->(allRelatedNodes)
WHERE r.revisionNo={1} AND (r)-[]->(allRelatedNodes)
RETURN a, relationships(p), nodes(p)
below query is cost effective. 下面的查询具有成本效益。 I get expected results while querying the in-browser database. 查询浏览器内数据库时,我得到了预期的结果。 However, while executing from my Java application, relations between nodes connected to the particular "Revision" are not fetched. 但是,从我的Java应用程序执行时,未获取连接到特定“修订版”的节点之间的关系。
PROFILE
MATCH (project:Project {name> :"test_local"})-[:HAS_REVISION]-
(revision:Revision{revisionNo:1})
WITH project,revision
MATCH p = (revision)-[]-(allRelatedNodes)
WITH project,revision,collect(p) as rs
RETURN project,revision,rs
Can anyone please help. 谁能帮忙。
I got this resolved using apoc.path.subgraphAll procedure. 我使用apoc.path.subgraphAll过程解决了这个问题。 my requirement was that "i need to get all nodes connected to revision and also relations between those nodes connected to revision node". 我的要求是“我需要使所有节点都连接到修订版,并且还要使那些节点之间连接到修订版节点”。 second query gave desired result in neo4j browser ui, but relations b/w nodes were not getting mapped in java neo4j entities. 第二个查询在neo4j浏览器ui中给出了所需的结果,但是在Java neo4j实体中未映射关系b / w节点。 Finally this is what I did, match (project:Project {name :{0}})-[:HAS_REVISION]- " + "(revision:Revision{revisionNo:{1}}) " + "call apoc.path.subgraphAll(revision,{maxLevel:1}) yield nodes,relationships " + "return nodes,relationships;
最后,这就是我所做的, match (project:Project {name :{0}})-[:HAS_REVISION]- " + "(revision:Revision{revisionNo:{1}}) " + "call apoc.path.subgraphAll(revision,{maxLevel:1}) yield nodes,relationships " + "return nodes,relationships;
manually copied apoc jar in the plugins folder of neo4j. 在neo4j的plugins文件夹中手动复制apoc jar。 Thanks everybody for your suggestions. 谢谢大家的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.