简体   繁体   English

Neo4j:路径中节点之间的返回关系

[英]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.

相关问题 Neo4j - 仅当所有节点对之间的关​​系属性存在时才返回路径 - Neo4j - Return a path only when relationship property between all of the pairs of nodes exists 在neo4j中创建节点之间的关系 - Create relationship between nodes in neo4j neo4j - 三个节点之间的关系 - neo4j - Relationship between three nodes 如何查询Neo4j节点及其之间的关系? - How to query Neo4j nodes and the relationship between the nodes? 写一个返回的查询,返回neo4j中两个节点之间的补充关系 - write a query that return that return supplementary relationship between two nodes in neo4j Neo4j的最短路径挖掘算法是否要求节点之间的关系方向一致 - Does the shortest path mining algorithm of Neo4j require the relationship between nodes to be in the same direction Scala / Neo4J-删除/删除节点之间的关系路径并返回true或false - Scala / Neo4J - Removing/ deleting a relationship path between nodes and returning true or false as result 存储neo4j的朋友[节点]之间的关系路径并在将来进行更新 - Storing relationship path between friends[nodes] from neo4j and updating it in future Neo4j-根据关系属性查找两个节点之间的最短路径 - Neo4j - Finding the Shortest Path between two nodes based on relationship property neo4j中的三个节点之间的“之间”关系或图db - A “between” relationship between three nodes in neo4j or a graph db
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM