Neo4J query to do Group By on Nodes for same type of data

31 views
Skip to first unread message

Docers Docy

unread,
May 17, 2016, 10:47:25 PM5/17/16
to Neo4j

Following is what I created in Neo4j:

Nodes: Customer Names, Customer Address and Customer Contact

Linked these nodes based on common relationships between all three.


Data Model -> 

(a:Address)<-[:ADDRESS_AT]-(p:Person {name: '...'})-[:CONTACT_AT]->(c:Contact)

I can see all three nodes linked in Neo4j. Contact contain email and phone numbers so some cases customer name node is connected to email address, phone number and address.

In my learning curve I am asked to show how many same Contact (email, phone no) are used by different customer names also how many same address used by different customer names. Based on my little experience I tried few queries but couldn't  reach to results.

Tried following query ->

MATCH (person:Person)-[:CONTACT_AT]->(contact:Contact)
RETURN contact, COLLECT(person.name) AS names;

MATCH (person:Person)-[:ADDRESS_AT]->(address:Address)
RETURN address, COLLECT(person.name) AS names;

I tried with LIMIT 100 and 1000 but all addresses have only one node on display. Is it possible to display only the addresses that are linked to more than one customer names? Same for contact it is showing only one to one relationships.
I would like to limit query to show One Address used by Multiple Persons and One Contact (email, Phone No) used by Multiple Persons but no one to one relationship. 

Please guide. Thanks.












Michael Hunger

unread,
May 18, 2016, 12:55:37 AM5/18/16
to ne...@googlegroups.com

MATCH (person:Person)-[:ADDRESS_AT]->(address:Address)
WITH address, COLLECT(person.name) AS names
WHERE size(names) > 1
RETURN address, names;


> Am 17.05.2016 um 01:52 schrieb Docers Docy <doc...@gmail.com>:
>
>
> 0
> down vote
> favorite
> --
> You received this message because you are subscribed to the Google Groups "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages