I am trying to match a path with a particular criteria. On the matched paths I am trying to filter out the properties that each relationship of the path has [???]. My query does not run. Can someone please debug the following query:
MATCH path = (n:UrlNode {label: 'H'})-[r:PATH*]->(m:UrlNode)
WHERE ALL(rel IN relationships(path) WHERE ANY(key IN keys(rel) WHERE key CONTAINS 'H'))
AND NOT EXISTS { (m)-[:PATH]->(:UrlNode) }
WITH path, nodes(path) AS nodes, relationships(path) AS rels
UNWIND rels AS rel
WITH path, nodes, rel, [key IN keys(rel) WHERE key CONTAINS 'H'] AS filteredKeys
WITH path, nodes, rel, reduce(acc = {}, key IN filteredKeys | acc + { key: rel[key] }) AS filteredProperties
RETURN nodes,COLLECT({relationship: rel, properties: filteredProperties}) AS relations;
I have built the above on the following query which works
MATCH path = (n:UrlNode {label: 'H'})-[r:PATH*]->(m:UrlNode)
WHERE ALL(rel IN relationships(path) WHERE ANY(key IN keys(rel) WHERE key CONTAINS 'H'))
AND NOT EXISTS { (m)-[:PATH]->(:UrlNode) }
WITH path, nodes(path) AS nodes, relationships(path) AS rels
UNWIND rels AS rel
WITH path, nodes, rel, [key IN keys(rel) WHERE key CONTAINS 'H'] AS filteredKeys
RETURN nodes,rel,filteredKeys
1
The only syntax error I can see is in your merging of maps in the reduce()
function. Change it to the following:
reduce(acc = {}, key IN filteredKeys | acc{.*, key: rel[key] })
See the documentation on maps.