cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How can make groups/clusters , based on the weight of the relationship

I started by uploading my database and then I set the weight for all relationships by running this query :

match (a:Attributaires)--(h:Attributaires)
with a, count(h) as AttributaireCount
match (a)-[r]-()
set r.weight = AttributaireCount

Now I want to regroup/put in clusters , all '"Attributaires" that have the same relationships' weight .
How can I make this ? thanks in advance everyone 🙂

1 ACCEPTED SOLUTION

If i understand correctly from you are trying to find groups of nodes that have the same number of relationships.

I don't know how you want them returned but here is a simple query that would return that stream results:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
RETURN number_of_rels,collect(a) as members

If you want to write back results in the graph you could do:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
MERGE (cluster:Cluster{size: number_of_rels})
MERGE (a)-[:PART_OF]->(cluster)

View solution in original post

1 REPLY 1

If i understand correctly from you are trying to find groups of nodes that have the same number of relationships.

I don't know how you want them returned but here is a simple query that would return that stream results:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
RETURN number_of_rels,collect(a) as members

If you want to write back results in the graph you could do:

MATCH (a:Attributaires)
WITH a, size((a)--()) as number_of_rels
MERGE (cluster:Cluster{size: number_of_rels})
MERGE (a)-[:PART_OF]->(cluster)