Cypher:从路径

时间:2017-02-18 10:09:40

标签: neo4j cypher extract

我想从节点和关系中提取路径属性。 我可以使用以下查询单独为节点和关系执行此操作。

extract(n IN nodes(path)| n.name)

extract(r IN relationships(path)| r.metric)

是否有办法从列表中的路径元素中提取名称和指标,如下所示 [name1, metric1, name2, metric2, name3]

1 个答案:

答案 0 :(得分:3)

您可以使用reduce来组合数组:

WITH path,
     extract(n IN nodes(path)| n.name) as names,
     extract(r IN relationships(path)| r.metric) as metrics
RETURN HEAD(names) + 
       REDUCE(acc = [], i in RANGE(1,size(metrics)) | 
              acc  + metrics[i-1] + names[i])