3

How do I make sure each node label (not just the node itself) is unique in the path it traverses?

MATCH (customer:Customer { id: '123' })-[*]->(product:Product)
RETURN product

The behavior I want:

[Customer]->[Sale]->[Product]

What I don't want (The path contains a Sale twice):

[Customer]->[Sale]->[Department]->[Sale]->[Product]

I don't know the depth beforehand so using (customer:Customer)-[*2]->(product:Product) is not an option.

W4G1
  • 1,337
  • 1
  • 11
  • 15
  • I have tried to think in short bursts about your issue. I have an issue understanding why you have two identical labels for the things you want to differentiate with the query. On top of that, variable depth or structure adds to the complexity of the query since you are not sure where your label can occur. You can probably write a query that does this, but as you can see, it is not easy, so it doesn't make a lot of sense if this is an important query. Modeling data differently would be a better choice for overall future queries. – Ante Javor Dec 21 '22 at 15:35

1 Answers1

1

Is sale always the first relationship type in the path? If so, you could try this:

(customer)-[:Sale]->()-[rel*]->(product) where not [i in rel where type(i) = "Sale"]
bischrob
  • 544
  • 3
  • 10