how to add relationship within joined records in NEO4J

Viewed 28

i have two records ('orders' and 'menulist') that are joined with 'orderitem' by orderID nad menuID [1]: https://i.stack.imgur.com/5kF8R.png [2]: https://i.stack.imgur.com/sabUE.png [3]: https://i.stack.imgur.com/0sqk1.png

i was trying to promote each orderitem record into a relationship in the graph what I did is:

LOAD CSV WITH HEADERS FROM "file:///orders.csv" AS row
CREATE (n:Orders)
SET n = row

LOAD CSV WITH HEADERS FROM "file:///menulist.csv" AS row
CREATE (n:Menu)
SET n = row

CREATE INDEX FOR (m:Menu) ON (m.MenuID)
CREATE INDEX FOR (o:Orders) ON (o.OrderID)

LOAD CSV WITH HEADERS FROM "file:///orderitem.csv" AS row
MATCH  (m:Menu), (o:Orders)
WHERE m.MenuID = row.MenuID AND o.orderID = row.orderID
CREATE (o)-[oi:CONTAINS]->(m)
SET oi = row,
oi.Quantity = toInteger(row.Quantity)

but I got (no changes, no records), seems there is an error here, can anyone help to solve?

1 Answers

That is not the proper way of creating node from csv. Follow the examples found in this link: https://neo4j.com/docs/cypher-manual/current/clauses/load-csv/#load-csv-import-data-from-a-csv-file

In your example, remove the Set n = row because it will not assign the columns in the csv to each property in the node. You need to define the attributes one at a time. See below.

 LOAD CSV WITH HEADERS FROM "file:///orders.csv" AS row
 CREATE (  :Orders {ID: row.OrderID, <and so on> , paymentID: row.PaymentID  })

Also notice that the variable n in label :Orders is not needed.

Related