2
votes

I have a network of nodes which represent People which are connected by relationships (Emails).

The Receiver of the Email is m.slug

Based on: ()-[r]-(m)

I wish to split the property (in this case "Sender" / m.slug ie [email protected])and create a new node "Google.com" AS Company (i.e so I now have a set of Company nodes created from the existing information).

I want to then link Google (the company) to my Person Node ([email protected]).

--

How would you approach this, without creating multiple duplicate Company nodes? (i.e for [email protected] & [email protected] should be connected to the same Google.com Company Node).

Visual Representation of People and relationships

Example syntax of queries and relationship properties

1

1 Answers

1
votes

This is how you can ensure there is a unique Company node for each email address domain name, and associate it (via an AT relationship) with each Person with an email address in that domain. The domain name is lower-cased before storing, to ensure uniqueness, since email addresses frequently come with different casing.

MATCH (n:Person)
MERGE (c:Company {name: TOLOWER(SPLIT(n.slug, '@')[1])})
CREATE (n)-[:AT]->(c);

NOTE: The above query should only be executed ONCE, since the CREATE clause would create the relationship every time, even if it already exists. You can replace CREATE with MERGE if you need to run the query multiple times.