Search code examples
dgraph

Graph database: get common parent node


I want to select the first common boss for two employees in draph.

My model is simple:

name: string boss_of: uids

Lets assume the following data where each arrow denotes the boss_of edge:

A -> B
A -> C
B -> D
C -> E
E -> F
E -> G

So, given F And D the query should return A, for F and G the result is obviously E.

I tried using allofterms but found no solution as there may be a different number of nodes between the co-workers and their common boss. Is it possible at all to formulate such a query?

I am trying to explore dgraph (or graph databases at all), so maybe I am just overseeing something.


Solution

  • You can use K-Shortest Path Queries

    The middle one in the response is the closest common entity.