简体   繁体   中英

Neo4j -Failed to add Bidirectional ralationship

I am a newbie to neo4j, I started building relationships between the nodes. Uni directional relationships are created properly without throwing any error but the bi-directional relationship is throwing the syntax error. Here goes my query:

MATCH(a{word:"nothing"}),(b{word:"review"})
CREATE a-[r:coocr{val:1}]-(b)
RETURN r,s

Then ended up with this:

MATCH(a{word:"nothing"}),(b{word:"review"})
CREATE a-[r:coocr{val:1}]->(b)
CREATE a<-[s:coocr{val:1}]-(b)
RETURN r,s

How can I reduce the no.of relationships using bidirectional relationships.

Neo4j doesn't support creating bidirectional relationships, but you can query from either direction without any difference in performance.

If you want to represent different values/states going to/from then you'll want to create a relationship going in each direction. Otherwise you should just creating it in whatever direction makes most senses (or arbitrarily in some cases) and query bidirectionally like this:

MATCH (a{word:"nothing"})-[rel:coocr]-(b{word:"review"})
RETURN rel

Note that there's no greater than or less than to represent the end of the arrow.

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