Hello,
How would I count the number of relationships per each group of nodes? Here's a proxy of my data model:
The result that I want here is the table:
|City| Total Stores| First_Access| Second_Access| Third_Access|
|London|89|100|30|50|
|New York City|74|200|50|87|
|Munich|60|450|67|32|
|Chicago|50|239|58|25|
|Paris|30|140|31|32|
|Tokyo|20|20|22|12|
|Beijing|10|30|10|8|
I tried this Cypher query but it doesn't quite work:
MATCH(c:City)<-[:LOCATED_IN]-(s:Store)
RETURN DISTINCT
c.name as City,
count(DISTINCT s) AS `Total Stores`,
size((s)-[:FIRST_ACCESS]->()) AS First_Access,
size((s)-[:SECOND_ACCESS]->()) AS Second_Access,
size((s)-[:THIRD_ACCESS]->()) AS Third_Access
ORDER BY `Total Stores` DESC
This gives me duplicated rows like this:
|City| Total Stores| First_Access| Second_Access| Third_Access|
|London|49|0|0|0|
|London|49|100|30|50|
|New York City|74|200|50|87|
|Munich|30|0|0|0|
|Munich|30|450|67|32|
|Chicago|50|239|58|25|
|Paris|30|140|31|32|
|Tokyo|20|20|22|12|
|Beijing|10|0|0|8|
|Beijing|0|30|10|0|
Then I tried the following query:
MATCH(c:City)<-[:LOCATED_IN]-(s:Store)
RETURN DISTINCT
c.name as City,
count(DISTINCT s) AS `Total Stores`,
size(collect((s)-[:FIRST_ACCESS]->())) AS First_Access,
size(collect((s)-[:SECOND_ACCESS]->())) AS Second_Access,
size(collect((s)-[:THIRD_ACCESS]->())) AS Third_Access
ORDER BY `Total Stores` DESC
But this cypher query brings my laptop to a crawl and I'm waiting hours for this to finish executing. Is anyone aware of an apoc procedure that can help with this? Or is there a better way to write this query? I'm reading through the cypher cyntax guide and apoc docs, but I can't find what I need.
Here are my neo4j specifications:
dbms.memory.heap.initial_size=5G
dbms.memory.heap.max_size=5G
dbms.memory.pagecache.size=7G
neo4j version: Community 4.2.0
desktop version: 1.3.11