apoc.nodes.group
This procedure returns virtual nodes that can only be accessed by other APOC procedures. For more information, see Virtual Nodes & Relationships (Graph Projections). |
This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime. For more information, see the Cypher Manual → Parallel runtime. |
Syntax |
|
||
Description |
Allows for the aggregation of |
||
Input arguments |
Name |
Type |
Description |
|
|
The list of node labels to aggregate over. Use |
|
|
|
The property keys to group the nodes by. |
|
|
|
The first map specifies the node properties to aggregate with their corresponding aggregation functions, while the second map specifies the relationship properties for aggregation. The default is: |
|
|
|
|
|
Return arguments |
Name |
Type |
Description |
|
|
A list of grouped nodes represented as virtual nodes. |
|
|
|
A list of grouped relationships represented as virtual relationships. |
|
|
|
The grouping node. |
|
|
|
The grouping relationship. |
Usage Examples
The examples in this section are based on the following sample graph:
CREATE
(alice:Person {name:'Alice', gender:'female', age:32, kids:1}),
(bob:Person {name:'Bob', gender:'male', age:42, kids:3}),
(eve:Person {name:'Eve', gender:'female', age:28, kids:2}),
(graphs:Forum {name:'Graphs', members:23}),
(dbs:Forum {name:'Databases', members:42}),
(alice)-[:KNOWS {since:2017}]->(bob),
(eve)-[:KNOWS {since:2018}]->(bob),
(alice)-[:MEMBER_OF]->(graphs),
(alice)-[:MEMBER_OF]->(dbs),
(bob)-[:MEMBER_OF]->(dbs),
(eve)-[:MEMBER_OF]->(graphs);
CALL apoc.nodes.group(
['*'],
['gender'],
[{`*`:'count', age:'min'}, {`*`:'count'} ]
)
YIELD relationships
UNWIND relationships as rel
RETURN apoc.rel.startNode(rel) AS start, rel, apoc.rel.endNode(rel) AS end;
start | rel | end |
---|---|---|
(:Person {gender: "female", min_age: 28, `count_*`: 2}) |
[:MEMBER_OF {`count_*`: 3}] |
(:Forum {gender: NULL, `count_*`: 2}) |
(:Person {gender: "female", min_age: 28, `count_*`: 2}) |
[:KNOWS {`count_*`: 2}] |
(:Person {gender: "male", min_age: 42, `count_*`: 1}) |
(:Person {gender: "female", min_age: 28, `count_*`: 2}) |
[:KNOWS {`count_*`: 2}] |
(:Person {gender: "male", min_age: 42, `count_*`: 1}) |
(:Person {gender: "male", min_age: 42, `count_*`: 1}) |
[:MEMBER_OF {`count_*`: 1}] |
(:Forum {gender: NULL, `count_*`: 2}) |