大约有1000个节点,3600个关系 和许多人建立关系。 有查询sql:
match p=(:Devices{name:"123.123.123.208"})-[r:Cost*1..7]->(:Devices{name:"123.123.123.20"})
with p,reduce(x=0,a in relationships(p)|x+a.Cost) as value
order by value desc
limit 1
return p;
答案 0 :(得分:0)
为避免遍历循环,您可能需要利用APOC Procedures,特别是path expansion procs:
MATCH (start:Devices{name:"123.123.123.208"}), (end:Devices{name:"123.123.123.20"})
CALL apoc.path.expandConfig(start, {terminatorNodes:[end], relationshipFilter:'Cost>', minLevel:1, maxLevel:7, uniqueness:'NODE_PATH'}) YIELD path
WITH path, reduce(x=0,a in relationships(path)|x+a.Cost) as value
ORDER BY value DESC
LIMIT 1
RETURN path;
NODE_PATH唯一性确保每个路径不能多次使用一个节点。