Obtain separate graph for each mapping

cypher

(Mithil Dave) #1

I have a neo4j database with hundreds of nodes. I want to ask a query to return a graph of a particular pattern.

It returns me all the possible mappings in just one result for the asked query. For example, if there are two possible mappings for a query where the first mapping result has nodes n1,n2,n3 and second mapping result has nodes n2,n4,n5 then it will return me the graph formed by both the mapped pattern combined(i.e n1,n2,n3,n4,n5).

Is there any way that I can see two different graph (n1,n2,n3) and (n2,n4,n5) separated from each other for each individual mapping. Even if n2 is common between them.

Please help me out.


(Michael Hunger) #2

I think what you're seeing is that the neo4j browser combines those.

If you look at the table view you should see them individually.

You could also use the apoc virtual node and relationship functions to turn each path into it's own virtual graph.

e.g.

match path = (a)-[r1]->(b)-[r2]->(c)
with * limit 10
with *, apoc.create.vNode(labels(a),properties(a)) as va,apoc.create.vNode(labels(b),properties(b)) as vb,apoc.create.vNode(labels(c),properties(c)) as vc
return va,vb, vc,apoc.create.vRelationship(va,type(r1),properties(r1),vb) as vr1,apoc.create.vRelationship(vb,type(r2),properties(r2),vc) as vr2

I guess there should be a function which creates a virtual path from a path, I add an APOC issue.


(Mithil Dave) #3

Yes, the table shows it individually but I need the graphs. Thanks I will try it with Apoc.


(Michael Hunger) #4

Did it work for you?