Reputation: 1357
I have this kind of large Graph in my database where there are other things, but I just got it for a sample.
I have a scenario where I reach node 6, asking different questions. The questions are different based on the parent node. If it is node 1, the questions are different, and for node 2, the questions are different.
When I reach Node 6, I want to detect which path it followed to get Node 6. Is there any way I could do that?
Here is my create cypher
CREATE (feat1:FEATURE {name: 'Login', desc: 'Customer Login'}),
(feat2:FEATURE {name: 'Profile', desc: 'Customer PROFILE'}),
(R1:RULE {name:'R1',question:'q1'}),
(Auth1:THREAT {name: 'auth1', desc: '', impact: ''}),
(Auth2:THREAT {name: 'auth2', desc: '' ,impact: ''}),
(av_WEB_LOG:Attack_Vector {name: 'WEB_LOG',
desc: ''}),
(feat1)-[:HAS]->(Auth1),
(feat2)-[:HAS]->(Auth2),
(feat2)-[:HAS]->(Auth1),
(Auth1)-[:HAS]->(R1),
(Auth2)-[:HAS]->(R1),
(R1)-[:HAS]->(av_WEB_LOG),
Upvotes: 1
Views: 132
Reputation: 12684
This simple script will tell you if the web_login has a path from Login or from Profile. Note that CASE WHEN ELSE will only give you one result, either path1 or path2 or no path. The notation [:HAS*3] means there are 3 jumps from Login to the target Node.
MATCH (n:Attack_Vector {name: 'WEB_LOG'})
WITH CASE
WHEN exists (
(n)-[ :HAS*3]-(:FEATURE {name: 'Login'})
) THEN 'path1'
WHEN exists (
(n)-[ :HAS*3]-(:FEATURE {name: 'Profile'})
) THEN 'path2'
ELSE
'no path'
END as p
RETURN p
Upvotes: 1