Friday 28 April 2017

Node4j get multilevel relational nodes in a subgraph

I want to get nodes in a relation in a subgraph For example:

A-BELONGS->B
B-BELONGS->C
C-REQUIRES->B
C-REQUIRES->H
B-REQUIRES->P

So I want to start at A, get all the nodes recursively which have a BELONGS relation, i.e. A,B,C, and then get the nodes which are in REQUIRES relation to those nodes but not in BELONGS relationship subgraph, i.e. H and P, but not B. But I want to return only those nodes in a REQUIRES relation.

I've written the query like this:

MATCH (node:Node {name: 'A'})-[:BELONGS*]->(dep)
USING collect(node) + collect(dep) as nodes
WITH (dep)-[:REQUIRES]->(req)
return disinct req

Here I expect to get only P and H. But that is not what I am getting. What is wrong with this query?



via poushy

No comments:

Post a Comment