How to group or merge virtual relationship created using apoc.create.vRelationship among nodes in neo4j?

无人久伴 提交于 2020-01-25 08:00:06

问题


There is a set of artists, from which some artists create a temporary group and organize a event in any city. After it different groups organize events in different city or same city as done by some other group. I want to query the data when artist A participates in the event then the events done in same city by Artist B in a series of Dates with below Cypher query but get duplicate virtual relationship for Artist A & Event and also for Event & City.

MATCH seriesB = (bArtist:Artist)-[:HAS_PARTICIPATED]->(bEventArtists:EventArtists)-[:ORGANIZED]->(bEvent:Event)<-[:HAS_EVENT]-(bCityActivityDate:CityActivityDate)<-[:HAS_ACTIVITY_DATE]-(bCity:City), seriesA = (aArtist:Artist)-[:HAS_PARTICIPATED]->(aEventArtists:EventArtists)-[:ORGANIZED]->(aEvent:Event)<-[:HAS_EVENT]-(aCityActivityDate:CityActivityDate)<-[:HAS_ACTIVITY_DATE]-(aCity:City)
WHERE bArtist.name = 'ROCKON' and aArtist.name = 'SUN RISERS' and  bCityEventDate.cityId = aCityEventDate.cityId 
and aCityEventDate.eventDate< bCityEventDate.eventDate

WITH distinct bArtist,bEvent
,apoc.create.vRelationship(bArtist,'B_PERFORMED_IN',{},bEvent) as bPerformedRel
,apoc.create.vRelationship(aArtist,'A_PERFORMED_IN',{},aEvent) as aPerformedRel
,apoc.create.vRelationship(bCity,'INVITED_B',{},bEvent) as bInvitedRel
,apoc.create.vRelationship(aCity,'INVITED_A'',{},aEvent) as aInvitedRel
,bCity,aEvent,aArtist,aCity limit 5
RETURN *

Here for example if A has perfomed only single time in Paris and then different groups also performed in Paris each time with random artists. Lets say two times Artis B also performed in Paris then above query create two virtual relationship edges of relation for each relation between (aArtist & aEvent) and also for (aCity & aEvent). As A has performed only once there should be only one edge but it increase as per the relation between (bArtist & bEvent) for the same city.

来源:https://stackoverflow.com/questions/59465211/how-to-group-or-merge-virtual-relationship-created-using-apoc-create-vrelationsh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!