Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-09-2020 12:14 AM
Now our team use neo4j as a tool to implement MDM solution, we create all system as a node and all data exchanges as relationship and labeled "OUT" in neo4j.
We want to query what kinds of data transfers more than 2 system, so we use the cypher like following
MATCH (E:System)-[r:OUT]->(A:System)-[p:OUT]->(C:System) where r.description=p.description return *
and we got the result
But we can only get data transfer exactly 2 system, how about 3,4 or more?
so we want to try use variable-length pattern to get the result. But how can we restrict all OUT relation with the same property in a set of result like
MATCH test = (E:System)-[r:OUT*2]->(C:System) where ALL r.description is same
thanks!
04-09-2020 01:21 AM
Hi,
maybe I can help you with this. I think what you can try is:
MATCH test = (E:System )-[:OUT*]-(C:System) WHERE all(r in relationships(test) WHERE r.description = "someDescription")
This will at least give you all the Systems (independent of number of relationships away) for A certain description.
If you want to have it for all descriptions, maybe you might need a match and an unwind statement beforehand, something like:
MATCH (E:System)-[r:OUT]->(C:System)
WITH DISTINCT r.description
COLLECT (r.description) AS allDescriptions
UNWIND allDescriptions AS someDescription
MATCH test = (E:System )-[:OUT*]-(C:System) WHERE all(r in relationships(test) WHERE r.description = someDescription)
No guarantee on the above code working since I haven't tested it on your node setup 😉
I hope this helps.
Cheers,
Elena
04-09-2020 04:30 AM
I would like to add two things
MATCH (E:System)-[r:OUT]->(C:System)
WITH DISTINCT r.description
COLLECT ( distinct r.description) AS allDescriptions
UNWIND allDescriptions AS someDescription
MATCH test = (E:System )-[:OUT*]-(C:System) WHERE all(r in relationships(test) WHERE r.description = someDescription)
04-09-2020 05:05 AM
Hi Vivek,
Thanks! but we got the cycle present, and I modified the [:OUT*] into [:OUT2..3] and it works, but I still want to know if I want to use [OUT] to search, is there any method to restrict, like by
n in nodes(test) where count(n)< 3
04-09-2020 06:12 AM
Sorry I did not understand your question
04-09-2020 07:28 PM
Hi Vivek,
Cause our system graph have cycle present, so when I use [:OUT*] to query, my neo4j will crash.
And I wonder know, to solve this problem, can I use some condition to restrict every count of nodes in one path can not larger then 2, that mean the path (a)-(b)-(a) is not meet the condition cause node "a" is present 2 times and (a)-(b)-(c)-(d) is matched cause every node in path is presented 1 times only.
All the sessions of the conference are now available online