Reputation: 31
I would like to extract from a path properties from nodes and relationships. I can do it separately for nodes and relationships using the following queries.
extract(n IN nodes(path)| n.name)
extract(r IN relationships(path)| r.metric)
Is there a way to extract names and metrics from path elements in a list that looks as following
[name1, metric1, name2, metric2, name3]
Upvotes: 2
Views: 1377
Reputation: 29172
You can use reduce
for combining arrays:
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])
Upvotes: 3