Variable length pattern not working when specifying label

(Nehero) #1

Hey, hopefully we're just missing something but can someone tell me if this isn't possible?

We're trying to match these two patterns here:


Using this query:

MATCH (user:User)-[:BELONGS_TO*0..]->(:Crew)-[:BELONGS_TO]->(:Company)

But we get no results back. However, doing this query works when we don't specify the :Crew label:

MATCH (user:User)-[:BELONGS_TO*0..]->()-[:BELONGS_TO]->(:Company)

Any ideas why you can't specify the label on the intermediate?

(Andrew Bowman) #2

Unless there's a bug, this path may not exist. Can you find in your graph a path in which the pattern matches? You may want to double-check for typos or casing mismatches, as well as checking the directions of the relationships.

(Nehero) #3

Thanks for responding!

If you look at the above picture, you can see 3 scenarios:

  1. Works as intended, path exists:
  1. Works when the user doesn't belong to a crew and we don't specify the :Crew label in the middle:
  1. Does not work when we run against the same path as in example 2 but specifying the :Crew label

Think it could be a bug?

(Andrew Bowman) #4

Doesn't look like a bug to me.

I would guess that the top image doesn't feature the same user as the others (please confirm the uid of the user in the top image (with 3 nodes).

The second image shows that these two nodes fit the pattern, with the :User with the provided uid not having any :Crew node it belongs to. It fits the pattern because it traverses 0 :BELONGS_TO relationships (so the empty node in the pattern is the same node as the :User node), then it traverses another :BELONGS_TO relationships to a :Company node.

The third image shows that there is no such pattern where the :User in question meets the pattern, since there is no :Crew node that is reachable via outgoing :BELONGS_TO relationships.