Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-25-2022 07:31 PM
Consider the following graph. Red nodes are called Entities and beige nodes are call Components. The CHILD_OF relationship between Entities, forms a tree of Entities. There are no cycles, and a single root, with id '#root'. Entities can have one or more Components attached to them, using the ATTACHED_TO relationship.
I need a query that takes an Entity ID and returns all the entities and components that are descendants of the entity with the given ID. The following query returns all the Entities, but does not return the Components of those entities.
MATCH (e:Entity {id: '#root'})
WITH e, [(e)<-[:CHILD_OF*]-(x) | x] as descendants
RETURN e, descendants
How can I modify this query to return the components also?
05-25-2022 09:47 PM
Try this:
MATCH (e:Entity {id: '#root'})
CALL apoc.path.spanningTree(e, {maxLevel:5}) YIELD path
RETURN path
This should produce the graph you displayed.
05-26-2022 07:00 AM
Thanks. I'm using Neo4j desktop and I get the following message to this query.
There is no procedure with the name `apoc.path.spanningTree` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.
I assume this means I need to install an extension. I'll look into that.
Can my query be modified to do what I want without an extension? I assume so.
Thanks!
05-26-2022 07:16 AM
Got it installed. Thanks.
05-26-2022 08:44 AM
You can use variable path length:
MATCH (e:Entity {id: '#root'})
MATCH p = (e)-[*..5]-(d)
RETURN p
All the sessions of the conference are now available online