我有此查询返回的数据集(图像):
MATCH(node:CXEligibilityRuleConstruct)-[:_properties]->(a)-->(spoke) with node
MATCH(node)<-[r:CXEHasChild]-(parent) where parent.nodeName='Network Segmentation' with node
Match(node)-[r:CXComponentHasCXRuleConstruct]-(cxc:CXComponentHierarchy{_type:'CXComponent'})
return node.elementLabel, collect( distinct cxc.elementLabel)
现在,如果用户输入了一个列表,例如:['Catalyst 9300','Cisco DNA Center','DNA Premier', 'ISE Appliance']
,我该如何返回与该匹配项有关的node.elementLabel
?
答案 0 :(得分:1)
假设用户列表以list
parameter的形式传递,并且您想精确匹配cxc.elementLabel
列表(元素顺序除外),这应该可行:
MATCH (node:CXEligibilityRuleConstruct)-[:_properties]->()-->()
MATCH (node)<-[:CXEHasChild]-(parent)
WHERE parent.nodeName = 'Network Segmentation'
WITH node
MATCH (node)-[:CXComponentHasCXRuleConstruct]-(cxc:CXComponentHierarchy)
WHERE cxc._type = 'CXComponent' AND apoc.coll.disjunction(cxc.elementLabel, $list) = []
RETURN node.elementLabel
APOC函数apoc.coll.disjunction(a, b)
返回一个列表,其中包含不在a
和b
中的元素。
[更新]
如果您不能使用APOC,并且$list
从来没有任何重复的元素,那么这应该可以工作:
MATCH (node:CXEligibilityRuleConstruct)-[:_properties]->()-->()
MATCH (node)<-[:CXEHasChild]-(parent)
WHERE parent.nodeName = 'Network Segmentation'
WITH node
MATCH (node)-[:CXComponentHasCXRuleConstruct]-(cxc:CXComponentHierarchy)
WHERE cxc._type = 'CXComponent' AND
SIZE(cxc.elementLabel) = SIZE($list) AND
ALL(x IN $list WHERE x IN cxc.elementLabel)
RETURN node.elementLabel