在Neo4j查询中过滤节点

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

我需要加入两个不同的图表。我想基于连接条件中的变量路径中的节点应用其他标准。以下查询工作正常。

query1 = 
match(a:iknode)-[*1..2]->(c:iknode)
match(d:flights17)-[r1]-(e:flights17)
where d.alias contains a.name return a,c

但是,它返回无关的记录。我需要在[* 1..2]部分中出现的节点上应用一些过滤器。这也有效。

match p = (a:fbnode)-[*1..2]->(c:fbnode)
where a.name = 'flights' and ANY (x IN nodes(p) WHERE x.name in ['leaving'])
return nodes(p)

我尝试了以下不起作用:

match p = (a:iknode)-[*1..2]->(c:iknode) 
(d:flights17)-[r1]-(e:flights17)
where d.alias contains a.name and ANY (x IN nodes(p) WHERE x.name in type(r1))
set e.f =c.name

我该如何重写上面的查询?

一种选择是从第一个查询中获取结果,然后在单独的查询(或python)中过滤结果。但是,我想在查询本身中这样做。 ALL可用于代替ANY。我还希望在过滤时排除开始和结束节点。

neo4j cypher
1个回答
0
投票

这有效:

match(d:flights17)-[r1]-(e:flights17) match p = (a:iknode)-[*1..2]->(c:iknode)  where d.alias contains a.name and ANY (x IN nodes(p) WHERE x.name in ['leaving']) set e.f =c.name

这也适用于消除开始和结束节点。节点(P)[1 ..- 1]

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