简体   繁体   English

密码查询以汇总关系属性

[英]Cypher Query to Aggregate Relationship Properties

I have a Neo4j graph containing PI and officer nodes, with relationships between them (each of which has an institution property). 我有一个Neo4j图,其中包含PI和Officer节点,以及它们之间的关系(每个节点都具有机构属性)。 I'm trying to create an inst_list property for each PI which lists all the institution properties of all of their edges. 我正在尝试为每个PI创建一个inst_list属性,该属性列出了其所有边缘的所有机构属性。 I'm still learning my way around Cypher, but confused as to why this is only creating an empty array for each PI: 我仍在学习有关Cypher的方法,但对为什么只为每个PI创建一个空数组感到困惑:

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH pi, a, COLLECT(distinct a.instituion) as insts
SET pi.inst_list=insts

It seems like it is an issue with COLLECT, as 好像是COLLECT的问题,因为

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH a.institution AS insts
RETURN insts

returns all the expected values. 返回所有期望值。

You just need to remove the a from your WITH clause. 您只需要从WITH子句中删除a

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH p, COLLECT(distinct a.institution) as insts
SET pi.inst_list=insts

By including the a , you were not collecting the institution property for each p , you were collecting it for each p and a , essentially doing nothing. 通过包含a ,您没有在为每个p收集institution属性,而是在为每个pa收集institution属性,实际上什么也没做。

I also assume you meant p and not pi ; 我还假设您的意思是p而不是pi in your query above, p is the identifier and pi is one of the labels. 在上面的查询中, p是标识符, pi是标签之一。 You also had a typo in institution , which is probably why your array was empty instead of the single value. 您还曾在institution输入过错,这可能是为什么数组为空而不是单个值的原因。

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

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