简体   繁体   中英

Compare data of two nodes of different labels in Neo4j with some property

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

with this query its giving cartesian issue and i want to carry forward both the nodes data for further use.

where I m lacking?

您可以使用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

This query may do what you want. It returns the unique cxc and csa pairs that pass all your tests.

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

For better performance, you should also create indexes on :CSAVHierarchy(_type) and :CXCustomerHierarchy(_type) .

This the solution I came up with

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM