简体   繁体   English

Neo4j - 无法添加双向关系

[英]Neo4j -Failed to add Bidirectional ralationship

I am a newbie to neo4j, I started building relationships between the nodes.我是 neo4j 的新手,我开始在节点之间建立关系。 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. Neo4j 不支持创建双向关系,但您可以从任一方向进行查询,而不会产生任何性能差异。

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.请注意,没有大于或小于表示箭头的末端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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