Cypher Neo4j创建两个节点之间的关系并避免双向关系

Cypher Neo4j创建两个节点之间的关系并避免双向关系,neo4j,cypher,Neo4j,Cypher,我的问题是: MATCH (a:Person)-[:friend]->(p:Person)<-[:friend]-(b:Person) WITH a, b, COUNT(p) as count WHERE count >= 2 CREATE (a)-[:friend {new: "yes"}]->(b) RETURN a,b,count 请注意,结果是重复的,这将在它们之间创建双向关系。name1-[:friend]->name2也意味着n

我的问题是:

   MATCH (a:Person)-[:friend]->(p:Person)<-[:friend]-(b:Person)
   WITH a, b, COUNT(p) as count
   WHERE count >= 2
   CREATE (a)-[:friend {new: "yes"}]->(b)
   RETURN a,b,count

请注意,结果是重复的,这将在它们之间创建双向关系。name1-[:friend]->name2也意味着name1是的,有一个技巧可以做到这一点:

MATCH (a:Person)-[:friend]->(p:Person)<-[:friend]-(b:Person)
WHERE ID(a) < ID(b)
WITH a, b, COUNT(p) as count
WHERE count >= 2
CREATE (a)-[:friend {new: "yes"}]->(b)
RETURN a,b,count
MATCH(a:Person)-[:friend]->(p:Person)=2
创建(a)-[:friend{new:“yes”}]->(b)
返回a、b、计数

变化是
其中ID(a)
确保只选择了两个方向中的一个

顺便说一句,我从Nicole White在Neo4j中的推荐引擎的优秀屏幕广播中学到了这个技巧:非常感谢。这就是我一直在寻找的东西很高兴听到这个消息!如果它对你有用,请接受answer@BrianUnderwood我试过你的建议。成功了!,但在我的例子中,在开始时,我的查询显示了3倍的关系,例如Grid26 Grid19,Grid19 Grid26,Grid19 Grid26,当我添加WHERE条件时,它显示了2倍。我认为我的查询匹配(g:Grid)有问题
   a             b            relationship
   name1         name2           friend
   name1         name2           friend
   name2         name2           friend
   name2         name2           friend
MATCH (a:Person)-[:friend]->(p:Person)<-[:friend]-(b:Person)
WHERE ID(a) < ID(b)
WITH a, b, COUNT(p) as count
WHERE count >= 2
CREATE (a)-[:friend {new: "yes"}]->(b)
RETURN a,b,count