比较Neo4j中具有不同标签的两个节点的数据的某些属性

时间:2019-03-20 07:09:44

标签: neo4j cypher

Match(csav:CSAVHierarchy) with csav


Match(cx:CXCustomerHierarchy) with cx

    Optional Match(csav)-[:CSAVCustomerHasChild]->(csa:CSAVHierarchy) where csa._type='CXCustomer' OR csa._type='CXCustomerBU'
    Optional Match(cx)-[:CXCustomerHasChild]->(cxc:CXCustomerHierarchy) where cxc._type='CXCustomer' OR  cxc._type='CXCustomerBU' 
    return
    CASE
    WHEN csa.ssid = cxc.ssid and csa.elementLabel = cxc.elementLabel
    THEN "yes"
    ELSE "No"  END As result

通过此查询,它给出了笛卡尔问题,我想结转两个节点的数据以备将来使用。

我缺少的地方?

3 个答案:

答案 0 :(得分:3)

您可以使用Apoc插件(请参见https://neo4j-contrib.github.io/neo4j-apoc-procedures):

Match(n:Person{ssid:"1234"}) with collect(n) as nodes CALL apoc.refactor.mergeNodes(nodes) YIELD node RETURN node

答案 1 :(得分:1)

此查询可能会执行您想要的操作。它返回通过所有测试的唯一cxccsa对。

MATCH (csa:CSAVHierarchy)
WHERE
  (:CSAVHierarchy)-[:CSAVCustomerHasChild]->(csa) AND
  csa._type='CXCustomer' OR csa._type='CXCustomerBU'
MATCH (cxc:CXCustomerHierarchy)
WHERE
  (:CXCustomerHierarchy)-[:CXCustomerHasChild]->(cxc) AND
  csa.ssid = cxc.ssid AND
  csa.elementLabel = cxc.elementLabel AND
  (cxc._type='CXCustomer' OR  cxc._type='CXCustomerBU')
RETURN cxc, csa

为了获得更好的性能,还应该在:CSAVHierarchy(_type):CXCustomerHierarchy(_type)上创建indexes

答案 2 :(得分:0)

这是我想出的解决方案

MATCH(cxc:CXCustomerHierarchy)-[:_properties]->(auditnode)-->(spoke)
 where cxc._type='CXCustomer' OR  cxc._type='CXCustomerBU' AND spoke.start_date <= 1554272198875 <= spoke.end_date AND spoke.status = "Confirmed"
 with cxc
 OPTIONAL MATCH (cxc)<-[r:CXCustomerHasChild]-(parent) with cxc
 MATCH(csav:CSAVHierarchy)-[:_properties]->(auditnode)-->(spoke) with cxc,csav
 where csav._type='CXCustomer' OR  csav._type='CXCustomerBU' AND spoke.start_date <= 1554272198875 <= spoke.end_date AND spoke.status = "Confirmed"
 OPTIONAL MATCH (csav)<-[r:CSAVCustomerHasChild]-(parent) with csav,cxc
return 
CASE
WHEN csav.sourceSystemId <> cxc.sourceSystemId , csav.elementLabel <> cxc.elementLabel
THEN csav.elementLabel
ELSE "SIMILAR DATA "  END As result