我想从节点和关系中提取路径属性。 我可以使用以下查询单独为节点和关系执行此操作。
extract(n IN nodes(path)| n.name)
extract(r IN relationships(path)| r.metric)
是否有办法从列表中的路径元素中提取名称和指标,如下所示
[name1, metric1, name2, metric2, name3]
答案 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])