cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Hide/replace nodes and realtions in a path with virtual relations/nodes

Hi all. I want to hide some of the data returned in my path by using virtual nodes/relations.

I created the virtual nodes successfully but upon returning the path, it is still showing the nodes and relations i am trying to hide. Is there any way that I can return the virtual relation in the same path object without creating a new object?

eg: original path = A->B->C->D->E (nodes to be hidden = c Therefore, if i want to replace it with a virtual relation then my path effectively should be A->B->D->E)

Although my virtual relationship is successfully created bw B and D node, it still returns the C node as well as A->c and C->D relations. Thanks in advance

10 REPLIES 10

Can you post her query? 

 

call {
match path = (n:A{Name:"xyz"})<-[e:BelongsTo]-(p:B)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, e as edge, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)-[:Uses]->(p:D)<-[:BelongsTo]-(:D)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (n:A{Name:"xyz"})-[e:BelongsTo]->(:E)<-[:BelongsTo]-(p:E)<-[:BelongsTo]-(:C)-[r:CanAccess]->(k)
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
union
match path = (k:F)-[e:BelongsTo]-(p:G)-[:BelongsTo]-(:G)-[r:isAttachedTo]->(n:A{Name:"xyz"})
return n as Identity, r.Effect as Effect, r.Action as Action, k as ResourceId, path, p, e as edge
}
with collect(distinct Effect) as EffectList, Identity, Action, ResourceId, collect(path) as paths, collect(p) as policies, edge
where size(EffectList) = 1 and EffectList[0] = "Allow"
with EffectList, Identity, Action, ResourceId, paths, policies, edge
unwind policies as p
return apoc.create.vRelationship(p, 'MyEdge', {Effect:"Allow"}, ResourceId) as relations, Identity,edge
Basically for eg in the first match I want to skip "C" node in the path and directly connect B->k

rudrakhsha_0-1671169749208.png

This is the original path i am getting
I want to replace it with a new path:

rudrakhsha_1-1671169852403.png

 

 

@rudrakhsha any solution on this. are you able to crack on this. I am also facing similar issue.

Thanks in advance

Can you describe you situation, so someone we can help?  

That is a lot.  It is hard to understand how it relates to your graph.  Anyways, try the following for the first path:

match (n:A{Name:"xyz"})<-[e:BelongsTo]-(p:B)<-[:BelongsTo]-(ps:C)-[r:CanAccess]->(k)
return n, e, p, k, apoc.create.vRelationship(p, 'MyEdge', {Effect:'Allow'}, k) as vRel

Also, you may be getting relationships you did not expect, as neo4j browser shows all relationships between displayed nodes by default. You can turn this off in the settings. Its the 'connect result nodes' checkbox at the bottom of the settings pane.

Screen Shot 2022-12-16 at 1.54.17 AM.png

Thanks for the reply. I still had one doubt though. This will help me create a path with the virtual relation we created but in case I have some different path like the 3rd union where i have to travel different number of nodes, I will have to return a total of 5 objects then. Then in that case how do I create a virtual relation as Union queries wont allow sending different number of columns/relation alias in cypher query.

@glilienfield 

You could return ‘null’ for the missing values, so all the unions return the same number. Also use generic names so they all have the same names, i.e., node1, rel1, node2, rel2, …

what is all the collect and unwinds for at the end. 

That is some logic level processing I am doing to filter out results according to my requirement...

Or, pack the results in an array, so each union returns a single item, then unwind the result to return the nodes and relationships. Arrays can contain elements of different types. 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online