如何才能在Neo4j中返回超过一定数量关系的节点?

时间:2015-04-06 23:04:30

标签: neo4j cypher

我遵循本教程:http://neo4j.com/developer/guide-import-csv/#_super_fast_batch_importer_for_huge_datasets

假设我想找到所有遭到超过5起投诉的公司。在此图表中,有两个节点Complaint和Company,以及类型" AGAINST"的有向边。从投诉到公司

MATCH (company)-[z:AGAINST]->(complaint) where COUNT(z) > 5 RETURN company

1 个答案:

答案 0 :(得分:1)

这是否符合您的需求?

// find the companies with complaints
MATCH (company)-[z:AGAINST]->(:Complaint) 
WITH company, count(*) as complaints
// return only the ones where there are more than 5 complaints
where complaints > 5
return company, complaints

如果您想要归还所有公司,投诉及其关系......

// find the companies with complaints
MATCH (company)-[z:AGAINST]->(c:Complaint)
// count the complaints and collect them separately with the relationships 
WITH company
, count(*) as num_complaints
, collect(z) as details
, collect(c) as complaints
// return only the ones where there are more than 5 complaints
where num_complaints > 4
return company, details, complaints