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.

Creating Relationship for Transaction Module

I would like to understand whether we would be able to achieve the following and guidance to achieve it:

For ex:-
Column headers :
from_accout,txn_date,txn_amount, txn_id,to_account
123,23-Aug-2020,100,txnid1,456
123,24-Aug-2020,120,txnid14,456
456,24-Aug-2020,500,txnid99,543
673,24-Aug-2020,200,txnid12,231

I will be creating relationship called "transfered_to" between "from_account" and "to_account" with txn_date , txn_amount and txn_id as relationship property

Whilst creating when there are transaction made to same account more than once I intended to create only one relationship where as it's relationship property values should get appended.

Considering the above example for first two rows , we should have create only one relationship where as it's relationship property should have the details of the both the transaction.

4 REPLIES 4

Hi,

At first we only created only all nodes.

LOAD CSV WITH HEADERS FROM 'file:///sampledata.csv' AS line
MERGE (:Account {id: line.from_account})
MERGE (:Account {id: line.to_account});

Then I created all relationships.

LOAD CSV WITH HEADERS FROM 'file:///sampledata.csv' AS line
MATCH (from:Account {id: line.from_account})
MATCH (to:Account {id: line.to_account})
MERGE (from)-[:TRANSFERED_TO {txn_date: line.txn_date, txn_amount: line.txn_amount, txn_id: line.txn_id}]->(to);

Cypher created two relationships between 123 and 456, which I think is fine.
I think it's not a good design to have multiple transaction properties in one relationship.
Does this answer your question?

Here is my approach:

LOAD CSV WITH HEADERS FROM 'file:///sampledata.csv' AS line
MERGE (from:Account {id: line.from_account})
MERGE (to:Account {id: line.to_account});
MERGE (trndte:TranDate {dte: line.txn_date})

MERGE (trnamt:TranAmt {amount: txn_amount, txn_id: line.txn_id})

MERGE (from)-[:TO_ACCOUNT]->(to)-[:TRAN_DATE]->(trndte)-[:TRAN_AMOUNT]->(trnamt)

For the same from, to, and date the  (trndte) node will have multiple branches one for each amount.
In your case (trndate) will have two branches one for amount 100 and another for 120.

Having a separate node for transaction date will help you in your data analysis.

Thanks a lot Ameya. It gives whole lot of another perspective to displaying the date. I am going to simulate this as well and update here the progress.

Thanks a lot Koji. I will try to emulate in my test and see how it goes with our Business.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online