Reputation: 447
I'm trying to find family relations.
For example I want to know what's the relation between me and my father's wife? It should return mother.
What's the relation between me and my mother's daughter? It should return sister.
This is what my graph looks like. There are 8 relations and 2 labels (Male or Female).
How can I achieve this without specifying any node? For example if I want to know the relation between me and my father's daughter.
I want to do something like MATCH () -[:Father]->()-[:Daughter]->()
and relationship between start and end node.
I'm sure this query is absolutely wrong but I hope you get an idea what I'm trying to achieve here.
Upvotes: 1
Views: 350
Reputation: 2007
So,
At first - you should always specify some nodes.
Let's create some data:
CREATE (me:Person)
CREATE (mother:Person)
CREATE (daughter:Person)
CREATE (me)-[:Son]->(mother)
CREATE (me)<-[:Mother]-(mother)
CREATE (me)-[:Brother]->(daughter)
CREATE (me)<-[:Sister]-(daughter)
CREATE (mother)-[:Mother]->(daughter)
CREATE (mother)<-[:Daughter]-(daughter)
What's the relation between me and my mother's daughter? It should return sister.
Now we can find anwser to your question:
MATCH (me)<-[:Mother]-()<-[:Daughter]-(she)
MATCH (me)<-[r]-(she)
RETURN type(r)
Result:
Sister
What we have been done:
For example I want to know what's the relation between me and my father's wife? It should return mother.
Here something like this should work:
MATCH (me)<-[:Father]-()<-[:Wife]-(she)
MATCH (me)<-[r]-(she)
RETURN type(r)
Result:
Mother
Upvotes: 5