Trying to display multiple relationships between nodes

Hey guys, I'm relatively new to NEO4J. I'm using desktop to make a graph database for an email dataset. I have written some code and it seems to run correctly but it is not displaying multiple relationships between nodes.

**LOAD CSV WITH HEADERS FROM "file:///dummy_data.csv" AS row **

CREATE (s:Sender{from_send: row.From_User })

CREATE (r:Receiver{to_send: row.To_User })

MERGE (s)-[e:EMAILED{date: row.Date,time: row.Time,day: row.Day,subject: row.Subject, message_id: row.Msg_ID}]->(r)

RETURN s,r

I want each email address to display multiple relationships on a single node and not separately as shown

, is there something I'm doing wrong. Can anyone please guide

Hi @ahmedfazal405,

Welcome to the Community!!

Instead of Create Try Merge
MERGE (s:Sender{from_send: row.From_User })

MERGE (r:Receiver{to_send: row.To_User })

MERGE (s)-[e:EMAILED{date: row.Date,time: row.Time,day: row.Day,subject: row.Subject, message_id: row.Msg_ID}]->(r)

RETURN s,r

I think the fundamental misunderstanding is your division of senders and receivers as different nodes. If you truly want separate :Sender and :Receiver nodes then Vivek's query usign MERGE is the right way to go.

But I think you might be better served by having some central user node, and letting the role of sender or receiver be a function of the relationship between them:

MERGE (s:User {id:row.From_User})
MERGE (r:User {id:row.To_User})

MERGE (s)-[e:EMAILED{date: row.Date,time: row.Time,day: row.Day,subject: row.Subject, message_id: row.Msg_ID}]->(r)

RETURN s,r

This way you use a common node type for a user whether they're a sender or a receiver.

It's best that you back this kind of model with an index on :User(id) so the lookups of your sender and receiver are quick.

You might also consider if you will have a need to lookup emails by properties, or handle email threading, or handle emails to multiple receivers, in which case it may be better to model emails as their own nodes (being sent by a :User and received by potentially multiple :Users) rather than as simple relationships.

1 Like

Thank you. This does solve my problem.

I understand what you're implying. I do think it might be a better approach to tackle the problem the way you've mentioned. I'll try and look into that as well. Thank you for your help