我怎样才能在 Neo4j 中只有 return 个具有超过一定数量关系的节点?

How can I only return nodes with over a certain number of relationships in Neo4j?

我正在学习本教程:http://neo4j.com/developer/guide-import-csv/#_super_fast_batch_importer_for_huge_datasets

假设我想找出所有被投诉超过5次的公司。在此图中,有两个节点 Complaint 和 Company,以及从 Complaint 到 Company

类型 "AGAINST" 的有向边
MATCH (company)-[z:AGAINST]->(complaint) where COUNT(z) > 5 RETURN company

这是否满足您的需求?

// 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

如果您想return所有公司、投诉及其关系...

// 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