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