cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

how to query a tree in graph dynamically with a schema tree

ourdark
Node

I have a graph with cycles, and I want query the data in difference scenario according to a schema tree.

The data like this:

Custom->Order->Product
             ->Service
        ->Country

https://i.stack.imgur.com/ePF1s.png

and business want custom nation info and services, according to a schema tree.

Custom->Order->Service
      ->Country

I can write a static query like this

match(c:Custom)-[r1:is]->(m:Country)
match(c)-[o:order]->(o1:Order)-[r2:has]->(s:Service)
return c,r1,m,o,o1,r2,s

https://i.stack.imgur.com/THqA1.png

BUT the schema tree will be more complex, how can I make a query dynamic with the schema tree?
The question also on StackOverflow:
https://stackoverflow.com/questions/72682032/how-to-query-a-tree-in-graph-dynamically-with-a-schema-...

Test data:

create (r:root{name:'root'})
CREATE (c1:Custom{name:'alex'})
CREATE (c2:Custom{name:'jerry'})
CREATE (o1:Order{no:'a-1'})
CREATE (o2:Order{no:'a-2'})
CREATE (p1:Product{name:'apple'})
CREATE (p2:Product{name:'banana'})
CREATE (s1:Service{name:'service1'})
CREATE (s2:Service{name:'service2'})
CREATE (m1:Country{name:'us'})
CREATE (m2:Country{name:'au'})

create (r)-[a:root]->(c1)
create (r)-[b:root]->(c2)

create (c1)-[r1:order]->(o1)-[rr1:category]->(p1)
create (c2)-[r2:order]->(o2)-[rr2:category]->(p2)
create (o1)-[r3:has]->(s1)
create (o2)-[r4:has]->(s2)

create (c1)-[r5:is]->(m1)
create (c2)-[r6:is]->(m2)

Stackoverflow: https://stackoverflow.com/questions/72682032/how-to-query-a-tree-in-graph-dynamically-with-a-schema-...

Github:https://github.com/neo4j/neo4j/issues/12898

2 REPLIES 2

Hi @ourdark ,

Based on what I read on your StackOverflow reply, I think you may like taking a look into https://neo4j.com/labs/apoc/4.1/graph-querying/expand-paths-config/ as already suggested. In particular, you may like checking the behavior of *relationshipFilter* and *labelFilter*.

 

Oh, y’all wanted a twist, ey?

Hi @bennu_neo 

Thanks for your information, good to know best way we have here.