简体   繁体   中英

Creating relationship type between two nodes neo4j

I'm trying to create a relationship between two nodes and for some reason I am unable to do to.

MATCH (C:Company {Company: 'Node1'})
MATCH (J:Company {Company: 'Node2'})
MERGE (C)-[:Partner]-(J);

I'm getting the result (no changes, no records). Before trying to create this relationship, I uploaded a csv with the following cypher:

LOAD CSV WITH HEADERS FROM 'FILE:///company_info.csv' AS line
MERGE (C:Company {Company: line.Company })
ON CREATE SET
C.Partner = line.Partner,
C.Product = line.Product,
C.Partners = line.Partners,
C.Customers = line.Customers
ON MATCH SET
C.Partner = line.Partner,
C.Product = line.Product,
C.Partners = line.Partners,
C.Customers = line.Customers

I know that the C.Partner = line.Partner created a partner property not a relationship type. Any suggestions on what I can do here to create the relationship type?

So, according to a comment to the other answer, your actual issue is that you created a Company node with the wrong property value ("Node1 " instead of "Node1"). Therefore, your first MATCH clause failed.

To change the node property value from "Node1 " to "Node1" via Cypher, you can do this:

MATCH (c:Company {Company: 'Node1 '})
SET c.Company = 'Node1';

If this is a general problem, you can trim whitespace from both ends of that property value in all Company nodes this way:

MATCH (c:Company)
SET c.Company = TRIM(c.Company);

If you just want to trim on the right side, can can use the RTRIM function instead of TRIM .

You need to provide a direction for the relationship.

MATCH (C:Company {Company: 'Node1'})
MATCH (J:Company {Company: 'Node2'})
MERGE (C)-[:Partner]->(J);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM