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.

Problems with responde of cypher-pattern-varlength like (a)-[[:KNOWS*1..3]]->(b)

rob2
Node Clone

Hello

I have read through the following post, but do not quite understand the response i get in the example ..

also from the article above
2X_1_159dda96bac806c6f279880f5069847db4a99167.png

when i do

(a)-[[:KNOWS*1..3]]->(b)
WHERE a.name = 'Anders'
return a.name, b.name

I get as result

  • "Anders" "Dilshad"
  • "Anders" "Cesar"
  • "Anders" "Becky"
  • "Anders" "Filipa"
  • "Anders" "George"

what I need (would like to have) is

  • "Anders" "Dilshad"
  • "Anders" "Cesar"
  • "Anders" "Becky"
  • "Dilshad" "Filipa"
  • "Cesar" "George"
  • "Becky" "George"

any simple solution for that?
Thanks rob

1 REPLY 1

clem
Graph Steward

The query means "Who does Anders know directly or indirectly (with up to 3 jumps)"

The query you might be wanting is "who knows who directly).

That would be:

(a)-[[:KNOWS]]->(b)
return a.name, b.name  // this will have duplicates though, which could be removed with sorting and distinct.

Or maybe you mean "who know who within 3 hops of Anders"

Then I think it would be something like except it wouldn't include people directly associated with Anders. (I can't quite figure out a neat short query for that....)

(a)-[[:KNOWS*1..3]]->(someone_in_anders_circle)
WHERE a.name = 'Anders'
MATCH (someone_in_anders_circle)-[:KNOWS]->(b)