Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-17-2020 09:33 AM
I have a query that matches a pattern with multiple relationships and node types. Within that pattern one relationship is of variable length and has a property which contains a list of values. How do I collect that list in my query. I'm trying -
match (s:SMA)-[r:ASSOCIATED_WITH]->(d:DataSet)-[r1:LINEAGE*]->(d1:DataSet)<-[r2:ASSOCIATED_WITH]-(s1:SMA)
with s,s1, count(*) as count, unwind r1 as rel
with s,s1,count, collect(distinct(rel.relationKeys)) as relationKeys
merge (s)-[r3:CONNECTED_TO]->(s1)
set r3.count=count
set r3.relationKeys=relationKeys
But I gt the error -
Thank you.
Solved! Go to Solution.
03-19-2020 01:35 AM
Okay nevermind. This worked-
match (s:SMA)-[r:ASSOCIATED_WITH]->(d:DataSet)-[r1:LINEAGE*]->(d1:DataSet)<-[r2:ASSOCIATED_WITH]-(s1:SMA)
unwind r1 as rel
unwind rel.relationKeys as rKeys
with s,s1, count(*) as count, rKeys
with s,s1,count, collect(rKeys) as relationKeys
merge (s)-[r3:CONNECTED_TO]->(s1)
set r3.count=count
set r3.relationKeys=relationKeys
03-17-2020 09:54 AM
It is syntax error .
I do not think you can have With x,y, unwind a as k.
unwind is to take each element of the given list
03-17-2020 10:02 AM
UNWIND is its own clause, you cannot embed that within a WITH clause.
Using a variable on the var-length relationship part of the pattern is deprecated. You might consider breaking the pattern down into parts, isolating the var-length part and using a path variable on that:
MATCH (s:SMA)-[:ASSOCIATED_WITH]->(d:DataSet)
MATCH path = (d)-[:LINEAGE*]->(d1:DataSet)
MATCH (d1)<-[:ASSOCIATED_WITH]-(s1:SMA)
UNWIND relationships(path) as rel
WITH s, s1, count(*) as count, collect(distinct(rel.relationKeys)) as relationKeys
MERGE (s)-[r3:CONNECTED_TO]->(s1)
SET r3.count=count
SET r3.relationKeys=relationKeys
03-19-2020 12:24 AM
I get the following error-
rel.relationKeys
itself is a list. So in this it's trying to collect a list into a list. Could that be why?
03-19-2020 01:35 AM
Okay nevermind. This worked-
match (s:SMA)-[r:ASSOCIATED_WITH]->(d:DataSet)-[r1:LINEAGE*]->(d1:DataSet)<-[r2:ASSOCIATED_WITH]-(s1:SMA)
unwind r1 as rel
unwind rel.relationKeys as rKeys
with s,s1, count(*) as count, rKeys
with s,s1,count, collect(rKeys) as relationKeys
merge (s)-[r3:CONNECTED_TO]->(s1)
set r3.count=count
set r3.relationKeys=relationKeys
All the sessions of the conference are now available online