getting relationships when cypher when querying for shortestPath

122 Views Asked by At

I am trying to find the shortest Path between two nodes and I would like to get the relationships(start node, end node and type) so I could generate a Subgraph in Java.

I am using this cypher :

MATCH (nodeA),(nodeB), p = shortestPath((nodeA)-[*..15]-(nodeB)) WHERE ID(nodeA) = 1332076 AND ID(nodeB) = 1459451 UNWIND nodes(p) as n UNWIND relationships(p) as r RETURN collect(distinct { id : id(n), labels : labels(n), data: n}) as nodes, collect(distinct r) as relationships

My problem is the relationships are returned in a format that I don't understand. Like this :

{ "TFFamily": "MADS", "Category": "DIRECT", "PubMedID": "UNKNOWN", "Reference": "NA", "Interaction": "UNCONFIRMED", "TargetType": "AT2G36590", "Confirmation": "NO", "isTF": "AT2G36590" } { "HIT_END": "104", "BLAST_alignement_length": "52", "BLAST_evalue": "4.00E-27", "HIT_START": "53", "BLAST_percentage_identity": "82.69", "percentage_match": "43.7", "QUERY_START": "58", "clusterid": "CLUSTER_5713", "QUERY_END": "109", "BLAST_mismatches": "9", "BLAST_nrofgaps": "0"}

what is exactly relationship(p)? Is there a way to get the startId, the endId and the type?

Thanks

EDIT :

Possible solution :

Not sure if this is the best option but I found there are startNode(r) and endNode(r)

" MATCH (nodeA),(nodeB), p = shortestPath((nodeA)-[%s*..%s]-(nodeB))" + //
                " WHERE ID(nodeA) = {1} AND ID(nodeB) = {2} " +  //
                " UNWIND nodes(p) as n" + //
                " UNWIND relationships(p) as r" + //
                " RETURN COLLECT(distinct { id : id(n), labels : labels(n), data: n}) as nodes, " + //
                " COLLECT(distinct { relationshipId : ID(r), startId : ID(startNode(r)), labels : type(r) , endId: ID(endNode(r))}) as edges"; //
0

There are 0 best solutions below