如何从路径中提取标签?

时间:2016-05-31 15:56:23

标签: neo4j

我有查询

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,还匹配了孩子和父母,并且它的速度非常慢并且返回了大量的额外数据,我怎样才能与grand_children匹配?

1 个答案:

答案 0 :(得分:0)

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

这应该可以正常运作:

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)
...