Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-03-2022 11:23 AM - edited 11-03-2022 04:04 PM
I'm trying to query and return a hierarchy, where I want to be able to specimen the starting node and then get it's children and parents. Querying down children has a specific condition that needs to be met, that querying parents doesn't.
MATCH(i:Item {Id: 'some id'})
MATCH (i)-[:BELONGS_TO]->(c:Collection)-[:BELONGS_TO]->(:Project {Name: 'Project A'})
WITH i,c
optional match p1=(i)-[:DERIVED_FROM*]->(:Item)
optional match p2=(x:Item)-[:DERIVED_FROM*]->(i) where exists ((x)-[:BELONGS_TO]->(c))
with apoc.path.combine(p2, p1) AS path
with collect(path) as paths
call apoc.convert.toTree(paths)
YIELD value
RETURN value
Say I have a graph that looks like
a -> c
-> d -> e
b -> c
When I look at the hierarchy for item d, I returned json is a list of 3 different json objects (hierarchies). Seems like it's creating a tree based on the first path (going up from item d), then path from a and then path from b. I get that there will be multiple paths, but shouldn't apoc.convert.toTree combine these correctly?
Looks like p2 is return paths for a->d, b->d, and c->d. As it can't combine leaf nodes, I think the result should be a->d and b->d
A simpler example:
MATCH(i:Item {Id: '9ccf5efe-50d7-444c-8bbd-578feb861cab'})
MATCH (i)-[:BELONGS_TO]->(c:Collection)-[:BELONGS_TO]->(:Project {name: 'project a'})
WITH i,c
match p1=(i)-[:DERIVED_FROM*]->(:Item)
return p1
Say I have a -> b -> c. p1 will be a->b and a->b->c.
11-03-2022 03:18 PM - edited 11-03-2022 03:34 PM
I tried doing top down instead and it's better, but still can't get it quite right.
All the sessions of the conference are now available online