I am using Neo4j (version 3.4.1) and Spring-data-neo4j (5.0.10.RELEASE) in my application. I am also using OGM.
I have the below relationship between my nodes:
I want to find all the nodes in each path from node A to node F (in the order of traversal)
For e.g : For path A-->B-->F I want nodes A,B,F (in that order)
For path A-->C-->D-->F I want nodes A,C,D,F (in that order) etc.
I want to capture the nodes traversed in each path separately.
The cypher query that I came up with is as below:
@Query("MATCH p=((u:User{name:{nameOne}})-[:RELATED*1..3]-(v:User{name:{nameTwo}})) RETURN p")
List<User> getRelationBetweenUsers(@Param("nameOne") String nameOne, @Param("nameTwo") String nameTwo);
I also tried using List<List<User>>
as return type so as to get nodes on each path as separate list as below
@Query("MATCH p=((u:User{name:{nameOne}})-[:RELATED*1..3]-(v:User{name:{nameTwo}})) RETURN p")
List<List<User>> getRelationBetweenUsers(@Param("nameOne") String nameOne, @Param("nameTwo") String nameTwo);
However this returns all the nodes traversed in multiple paths together whereas I want them per path.
i.e result is List <A,B,C,D,F> where as what I want is
List<List<A,B,F>, List<A,C,D,F>, List<A,D,F>>.
Hope you get the idea.
Can anybody give some pointers/suggestions on how I can achieve the expected results.
Regards, Varun
A,B,C,D,F
is not a valid path, given the relationships in your illustration. Also, the result is a list of lists (of nodes), but you say that you are only getting back a list of nodes. Are you processing the result properly? – cybersamMATCH
query so that the relationship pattern contains an arrow to specify the direction (e.g,,-[:RELATED*1..3]->
). – cybersam