Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-13-2020 09:23 AM
I want to create a relationship with the same node
LOAD CSV WITH HEADERS FROM "file:///transactions.csv" AS line
WITH line
MERGE (c:Customer {loginId: line.`login_ID`, name: line.Customer_Name, age: line.Customer_Age, occupation: line.Customer_Occupation})
The above code is used to create a Customer node and then I write the code below to define a relationship called FRIEND on this same node.
LOAD CSV WITH HEADERS FROM "file:///transactions.csv" AS line
WITH line
MERGE (c:Customer {name:line.Customer_Name})
ON CREATE SET c.name = line.Customer
RETURN line
LOAD CSV WITH HEADERS FROM "file:///transactions.csv" AS line
WITH line
MATCH (c1:Customer {name:line.'Ben Thompson'}), (c2.Customer {name:line. 'Ricky Marty'})
MERGE (c1)-[:FRIEND]->(c2)
But when I run this code it doesn't work, what am I doing wrong here? The values 'Ben Thompson' and 'Ricky Marty' are present in the csv file and they appear as Ben, Thompson, and Ricky, Marty in the graph when I run
MATCH(n) RETURN(n)
since that's how they appear in the csv file being the first_name and last_name of a customer. Any help is appreciated. Thank you for your time in advance.
11-13-2020 02:30 PM
LOAD CSV WITH HEADERS FROM "file:///transactions.csv" AS line
WITH line
MATCH (c1:Customer {name:line.Customer_Name}), (c2:Customer {name:line.Customer_Name})
MERGE (c1)-[:FRIEND]->(c2)
This query works. I have a new question which would be that the above query creates a friend relationship with oneself. I don't want this and so I added a new line of code but I'm getting an error. This new code is as follows:
LOAD CSV WITH HEADERS FROM "file:///transactions.csv" AS line
WITH line
MATCH (c1:Customer {name:line.Customer_Name}), (c2:Customer {name:line.Customer_Name})
MERGE DISTINCT (c1)-[:FRIEND]->(c2)
WHERE c1.Customer_Name != c2.Customer_Name
Any help is appreciated. Thank you for your time in advance.
11-13-2020 04:33 PM
I think the WHERE
clause has to come after the MATCH
clause but before the MERGE
(or a CREATE
).
All the sessions of the conference are now available online