简体   繁体   English

Neo4j:根据节点表示路径密码查询结果

[英]Neo4j: Expres path cypher query result in terms of nodes

I have the following node structure Emp[e_id, e_name, e_bossid] . 我具有以下节点结构Emp[e_id, e_name, e_bossid] What is more I have a recursive query that exploit the database in recursive traversal on SELF relation e_bossid-[REPORTS_TO]->e_id 而且我有一个递归查询 ,该查询以SELF关系e_bossid-[REPORTS_TO]->e_id递归遍历方式利用数据库

MATCH (e:Employee) WHERE NOT (e)-[:REPORTS_TO]->()
SET e:Root;

MATCH path = (b:Root)<-[:REPORTS_TO*]-(e:Employee)
RETURN path
limit 1000;

However the result is PATH. 但是结果是PATH。 I would like to have result in form of NODES not the path. 我想以NODES而不是路径的形式产生结果。 I tried to use the nodes(path) , but it gives me an error: 我试图使用nodes(path) ,但是它给了我一个错误:

org.codehaus.jackson.map.JsonMappingException: Reference node not available (through reference chain: java.util.ArrayList[0]->java.util.HashMap["rel"]->java.util.HashMap["nodes(path)"]->java.util.ArrayList[0]->org.neo4j.rest.graphdb.entity.RestNode["restApi"]->org.neo4j.rest.graphdb.RestAPIFacade["direct"]->org.neo4j.rest.graphdb.ExecutingRestAPI["referenceNode"])

When I query without nodes(path) it seems to return only paths. 当我查询没有nodes(path)它似乎只返回路径。

How this should be done on the ground of cypher query? 应该如何基于密码查询来完成?

I'm not sure why you would want to get all possible paths in your organizational hierarchy. 我不确定为什么要在组织层次结构中获取所有可能的路径。 Maybe what you want to get is a set of paths from the leaves of the tree to the root of the tree, and to return each unique set as a row of nodes. 也许您想要获得的是一组从树的叶子到树的根的路径,并将每个唯一的集合返回为一行节点。

MATCH (b:Employee)
WHERE NOT (b)-[:REPORTS_TO]->()
MATCH (l:Employee)
WHERE NOT (l)<-[:REPORTS_TO]-()
MATCH p = shortestPath((b)<-[:REPORTS_TO*]-(l))
RETURN nodes(p) as reports

As far as your error goes, that looks like a bug, although I don't know what version of Neo4j you are using. 就您的错误而言,这似乎是一个错误,尽管我不知道您使用的是什么版本的Neo4j。 In all likelihood, your query won't complete because your Root employees are still a member of the Employee label. 由于您的Root员工仍然是Employee标签的成员,因此您的查询极有可能无法完成。 Which means that this pattern: MATCH path = (b:Root)<-[:REPORTS_TO*]-(e:Employee) matches the Root employees on each side of the variable length traversal. 这意味着该模式: MATCH path = (b:Root)<-[:REPORTS_TO*]-(e:Employee)与可变长度遍历的每一侧上的Root雇员匹配。

Give my query a try and let me know what happens. 试试看我的查询,让我知道会发生什么。

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

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