2016-05-31 125 views
0

我有查询如何从路径中提取标签?

MATCH (rootPerson:Person {uuid: '650wer0a-2374-11e6-aabd-ce6wqe3145e4'}) 
MATCH (mother:Rerson)<-[rel:MOTHER*0..4]-(rootPerson) 
WITH mother 
SKIP 1 
MATCH (children:Person)-[:MOTHER]->(mother) 
MATCH (grand_children:Person)-[:FATHER|:MOTHER]->(children) 
OPTIONAL MATCH (grand_children)-[:STUDY_AT]->(uni:University)... 

而问题是,Neo4j的匹配不只是grand_children但孩子和家长的欢迎,并它的速度非常慢下来,并返回了很多useles额外的数据,我该怎么做配套只有grand_children?

+0

这将是很好看的输入数据的一个例子和所期望的结果。你怎么试着得到这个结果。 –

回答

0

因为您不必要地使用可变长度路径模式(通过*0..4语法),所以您获得grand_children多代。

这应该正常工作:

MATCH (rootPerson:Person {uuid: '650wer0a-2374-11e6-aabd-ce6wqe3145e4'}) 
MATCH (rootPerson)-[:MOTHER]->(mother:Person) 
MATCH (children:Person)-[:MOTHER]->(mother:Person) 
MATCH (grand_children:Person)-[:FATHER|:MOTHER]->(children) 
OPTIONAL MATCH (grand_children)-[:STUDY_AT]->(uni:University) 
...