graph databases - Neo4j - Traversing from one node to another which are indirectly connected by parent Node -
i have specific case have 2 labels person , company. person has 2 nodes x , y , company has single node. both persons have relationship company has_employee.
i want find relationship between x , y i.e. work same company.
how in neo4j? given nodes x , y?
this depend on if you're looking specific connection (via :company node), or looking connection @ all.
let's :person nodes have name, , person nodes x , y have names 'x' , 'y', can match them. let's have index on :person(name) can lookup nodes quickly.
if query want "do persons x , y share same company", query this, returning company in question, is:
match (x:person{name:'x'})<-[:has_employee]-(comp:company)-[:has_employee]->(y:person{name:'y'}) return comp
but if don't know how these persons connected, or if they're connected, we'll want run shortestpath()
match between nodes, , see connects them.
it helps set upper bounds match. let's use 8 hops max.
match path=shortestpath((x:person{name:'x'})-[*..8]-(y:person{name:'y'})) return path
Comments
Post a Comment