简体   繁体   中英

Establish relationship among nodes in Neo4j

I am new to Neo4j. I have customer and product data into Neo4j. While loading I have not established any relationship among them. Now I want to establish relation among them like:

create (Customer1)-[:bought]->(Item1),(Customer1)-[:bought]->(Item2);

After I execute this statement it says Relationship established but as and when I try to access it like:

start n=node(*) match (n)-[:bought]->(items) where n.NodeName! = "Customer1" return items;

it says 0 rows. I think if it successfully establishes relationship it should give me 2 items, Item1 & Item2.

Any idea?

Apparently, you didn't set NodeName for your Customer1 node in your creation query. Try to modify it like this:

create (Customer1 { NodeName:'Customer1' }), (Item1 { NodeName:'Item1' }), (Item2 { NodeName:'Item2' }), (Customer1)-[:bought]->(Item1), (Customer1)-[:bought]->(Item2);

Then your second query should return 2 rows as you expected.

Update: Ok, I didn't understand the question correctly. So, you want to establish a relationship between already existing nodes. Then try this:

start Customer1=node:node_auto_index(NodeName='Customer1'), Item1=node:node_auto_index(NodeName='Item1'), Item2=node:node_auto_index(NodeName='Item2')
create (Customer1)-[:bought]->(Item1),(Customer1)-[:bought]->(Item2);

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