Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4J-如何在所有最短路径中排除自引用节点?_Neo4j - Fatal编程技术网

Neo4J-如何在所有最短路径中排除自引用节点?

Neo4J-如何在所有最短路径中排除自引用节点?,neo4j,Neo4j,我试图找到给定特定长度的所有最短路径。以下是我正在使用的查询: match (n:Person{email:'sam@gmail.com'}), (k:Person{email:'joseph@gmail.com'}), paths=allShortestPaths((n)-[r:CONNECTED_TO*..2]->(k)) where length(paths)=2 with collect(paths) as path unwind path as p return nodes(p)

我试图找到给定特定长度的所有最短路径。以下是我正在使用的查询:

match (n:Person{email:'sam@gmail.com'}),
(k:Person{email:'joseph@gmail.com'}),
paths=allShortestPaths((n)-[r:CONNECTED_TO*..2]->(k))
where length(paths)=2
with collect(paths) as path
unwind path as p
return nodes(p) as nodes,rels(p) as relations
问题是我在表单的数据库中有自引用节点

(n:Person{email:'sam@gmail.com'})-[:CONNECTED_TO]->
(n:Person{email:'sam@gmail.com'})

我想在最短路径查询中排除这些路径。谁能给我指引正确的方向。

您可以在最短路径调用后的WHERE子句中添加谓词,以排除以下情况:

match (n:Person{email:'sam@gmail.com'}),
(k:Person{email:'joseph@gmail.com'}),
path=allShortestPaths((n)-[:CONNECTED_TO*..2]->(k))
where length(path) = 2 and none(rel in relationships(path) where startNode(rel) = endNode(rel))
return nodes(path) as nodes, relationships(path) as relations