Kai Schlegel
Kai Schlegel

Reputation: 183

Cypher: multiple relationship types directed and undirected

I want to make a cypher query which includes two alternative types, but one of it is directed and one isn't. Is there a simple way to express this in cypher?

e.g. a -INHERITANCE-> b (directed)

x -EQUIVALENT- y (undirected)

Give me all nodes which n inherits or is equal to.

MATCH (n)-[INHERITANCE|EQUIVALENT *]-(n2) doesn't consider the directed characteristic of INHERITANCE

Upvotes: 2

Views: 444

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

Basically I see two approaches to that:

  1. use Cypher's UNION statement and join the results of the two matches
  2. run the match undirected and filter out the unwated matches using a where filter:

.

MATCH (a)-[r:INHERTIANCE|:EQUIVALENT]-(b)
WHERE type(r)="EQUIVALENT" OR endNode(r)=b
...

Just symbolic code above, have not tested it.

Upvotes: 3

Related Questions