Neo4j Cypher 查询过滤路径属性并返回键值对

问题描述 投票:0回答:1

嗨,我正在尝试将路径与特定条件进行匹配。在匹配的路径上,我试图过滤掉路径的每个关系所具有的属性。我的查询未运行。有人可以调试以下查询吗

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;

我已经在以下有效的查询上构建了上述内容

    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
neo4j cypher
1个回答
0
投票

我看到的唯一语法错误是在

reduce()
函数中合并地图。将其更改为以下内容:

reduce(acc = {}, key IN filteredKeys | acc{.*, key: rel[key] })

请参阅地图上的文档

© www.soinside.com 2019 - 2024. All rights reserved.