Thank you.
I have a question, like If I have data like this, why am I getting 8 different nodes when I import? Where as there as only 5 different customers where 3 customer have two order id's. Can I put those two order id's into properties instead of creating two different nodes for same person?
Your error is in adding all the properties to the 'Merge' clause, as these are used to find the node. For example, your orderId is not the same for the same customer, so a new node for that customer gets created. Instead, only include the property/properties that uniquely identify the node in the 'Merge' clauses properties. The remaining properties get set using a "SET" clause. The following is an example.
If you are tracking customers and their orders, you should have a data model that has Customer nodes and Order nodes. You related them with a relationship, which can be done during import.
You must change your data model and create an Order node.
// Create constraints
CREATE CONSTRAINT constraint_Customer_id IF NOT EXISTS FOR (c:Customer) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT constraint_Order_id IF NOT EXISTS FOR (o:Order) REQUIRE o.id IS UNIQUE;
// Create nodes
// Create Customer nodes
LOAD CSV WITH HEADERS FROM 'file:///Customer.csv' AS row
WITH row
MERGE (c:Customer {id: row.`Customer Code`})
SET c.name = row.`Customer Name`;
// Create Order nodes
LOAD CSV WITH HEADERS FROM 'file:///Customer.csv' AS row
WITH row
MERGE (:Order {id: row.`Order ID`});
// Create relationships
// Create ORDERED relationships
LOAD CSV WITH HEADERS FROM 'file:///Customer.csv' AS row
WITH row
MATCH (c:Customer {id: row.`Customer Code`})
MATCH (o:Order {id: row.`Order ID`})
MERGE (c)-[:ORDERED]->(o);