I have a neo4j graph: (person)-[like]-(fruit). I want to find person of person of person recursively using [like] and (fruit).
For example,
(John)-[like]->(Apple)<-[like]-(Sam)->[like]-(Banana)<-[like]-(Jack)-[like]->(Grape)<-[like]-(Lisa)...
How can I query this relationship using the neo4j?
If the sequence in your path is always a repetition of person, fruit, person ... and assuming only people like fruit and not the other way round, you could use a quantified path pattern like this:
If you want the paths to start at a particular person e.g.
'John', anchor the start node like so:If you want to include paths where only one person likes a fruit, use a
UNION:Note that some results may be subpaths of other results.
If you are using a version < 5.9 and have APOC installed, you can specify a sequence of labels and relationship types in the configuration of
apoc.path.expandConfig. This returns paths that start at'John':