Gremlin - Finding Specific Vertex within Path Traversed

59 Views Asked by At

I have a very simple graph in which I am returning (recursively) everyone, directly/indirectly, in my graph from a certain person that is older than 5. I am returning the person's properties but I also want to return a "derived relationship" based of a set of criteria, such as "closest female". Is there a better way to do this other than checking the path on each emitted vertex?

Queries:

Get everyone directly/indirectly related to 'A' over 5:

    g.V('a').
      repeat(out()).
      until(has('age',lte(5))).emit().
      project('props').
        by(elementMap()) 

Get everyone directly/indirectly related to 'A' over 5 and their closest female relative:

    g.V('a').
      repeat(out()).
      until(has('age', lte(5))).emit().as('x').
      project('props','closestFemale').
        by(elementMap()).
        by(coalesce(path().unfold().where(neq('x')).
           where(has('gender', 'F')).tail(), constant('n/a')))

Diagram image:
https://i.stack.imgur.com/HOTNg.png

0

There are 0 best solutions below