Problems finding 1 or more hops in the neighbourhood

Hi

i have read trough this

" ```
Match (a {name:"_AdminOrg"})-[r*1..3]->(b) Return Distinct
a, r, b "

but i have also read that the syntax "...*1..3" should not be used anymore:

so I came up with the following query

MATCH p = (n {name: "_AdminOrg"})-[r]-(m) return DISTINCT n, labels(n), relationships(p) AS r, type(r), m, labels(m);

  1. it works - but returns the wohle graph (i guess). what do i have to do if I ONLY want to have the next 2 or 3 hops?
  2. the dsitinct over the wohle "answer table" is not working. since i don't want to use -> i get each result (at least) twice

I really appreciate your help.
rob

Try this:

MATCH (c:A{ID:'123'}) 
CALL apoc.path.spanningTree(c, {maxLevel:3}) YIELD path
RETURN path

Change the level number to suit your query.

cool thanks i will !

Don't worry about that deprecated warning, we don't have any replacement for that feature, and it won't be removed until we have such a replacement. You can keep using a variable on a variable-length rel pattern.

That said, with a path variable (like your p), we can do what we need.

Also keep in mind that getting distinct node results (as in the apoc spanningTree() call) will not include any results where a different relationship is used to reach an already-visited node. You'll have to determine yourself what's more important for results, or if your results need to have their format changed.

I have this query at the moment

Match (n: process {guid: "96e7f3fe-cfa9-490c-9913-d288f738f76a"}) CALL apoc.path.spanningTree(n, {labelFilter: "status", relationshipFilter: "next_status|current_status", maxLevel: "3"}) YIELD path RETURN labels(n), path;

with labels(n) i can see the label of the source node

  1. how can i see the type of a relationship like type(r)
  2. how can I see the label of the destionations nodes? Lables(M)

Thanks for the answeres and your help!
rob

OHH it is easy ...

Match ((n: process {guid: "96e7f3fe-cfa9-490c-9913-d288f738f76a"})-[r]-(m)) CALL apoc.path.spanningTree(n, {labelFilter: "status", relationshipFilter: "next_status|current_status", maxLevel: "3"}) YIELD path RETURN labels(n), path, type(r), labels(m);

or is this a stupied way to do?

WITH nodes(path) as n1, relationships(path) as rels
UNWIND n1 as n11
UNWIND rels as r1
RETURN labels(n11) as lbl, type(r1) as rel

Wow - Thank you - This works!


MATCH (n: process {guid: "44b77af0-3b7e-4ce7-b74f-e967007cfdf8"})
CALL apoc.path.spanningTree(n, {maxLevel:3}) YIELD path WITH nodes(path) as nodes, relationships(path) as relationships
UNWIND nodes as nodesrow
UNWIND relationships as relationshipsrow
RETURN nodesrow as Node, labels(nodesrow) as Nodetype, relationshipsrow AS Relationship,type(relationshipsrow) AS RelationshipType

But is ther a way to Acess the NEXT element in the Row aswell? So i HAve access to the Left and the right Node of a relationship?

MATCH (n: process {guid: "44b77af0-3b7e-4ce7-b74f-e967007cfdf8"})
CALL apoc.path.spanningTree(n, {maxLevel:3}) YIELD path WITH nodes(path) as nodes, relationships(path) as relationships
UNWIND nodes as nodesrow
UNWIND relationships as relationshipsrow
RETURN nodesrow as LeftNode, labels(nodesrow) as LeftNodetype, relationshipsrow AS Relationship,type(relationshipsrow) AS RelationshipType, **nodesrow[1] as
RightNode , labels(nodesrow[1]) as RightNodetype**

This would help me a lot !
thansk rob

I also do the following DISTINCT at the moment to get less data

Match (n: process {guid: "5faacb1f-bf87-45a6-92fd-0ae735f74eee"})-[r]-(m) CALL apoc.path.spanningTree(n, {labelFilter: "status", relationshipFilter: "start_status|next_status|current_status", maxLevel: "4"}) YIELD path WITH nodes(path) as nodes, relationships(path) as relationships UNWIND nodes as nodesrow UNWIND relationships as relationshipsrow RETURN Distinct(nodesrow+labels(nodesrow)+relationshipsrow+type(relationshipsrow));

is this ok?