All paths between two nodes neo4j - incorrect answer (from neo4j)

半世苍凉 提交于 2019-12-25 03:07:53

问题


I want to get all path between two nodes with the relation "->" between them. I ask my DB using query (Cypher) like that:

START a=node(27), b=node(0) MATCH p=b<-[*]-a RETURN p 

In Neo4j visualization I get this:

Cypher query visualization

I want to get list of 3 path:

  • 27 -> 81 -> .... -> 0
  • 27 -> 67 -> .... -> 0
  • 27 -> 24 -> .... -> 0

but in the result I have got 6 paths (instead of 3). I want to figure out why.


回答1:


This happens because the query includes the 0 length paths starting from 'a'. If you look at the file you provided, the last three results are the same as the first three ones, except for the duplication of Node[0] at the beginning of the path.




回答2:


Your (OwlThing) has a [:subClassOf] relationship to itself. It doesn't show in the visualisation, but that's what

Node[0]{name:"owl:Thing"},:subClassOf[35]{},Node[0]{name:"owl:Thing"}

in your results means. For every path from that ends with (41)-[43]->(0) there is also a (41)-[43]->(0)-[35]->(0) which means your results are doubled.



来源:https://stackoverflow.com/questions/21894026/all-paths-between-two-nodes-neo4j-incorrect-answer-from-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!