1
votes

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.

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.

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.

1
Please, share your Java code. - Bruno Peres
The first cypher query looks like it's doing far more work than necessary because of things missing in the with clause. The second one looks OK, like it should work. Please post a java snippet and a more specific description of what you should be getting. You say you want relations between nodes connected to the particular "Revision" -- but you're collecting paths in the output of your query. So you may have a problem with how you're processing those paths for those relations. - FrobberOfBits

1 Answers

0
votes

I got this resolved using apoc.path.subgraphAll procedure. 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. 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;
manually copied apoc jar in the plugins folder of neo4j. Thanks everybody for your suggestions.