How to find if a vertex has at least 1 relationship/edge to a thousands of vertex with specific property


alvinl...@...
 

Let say I have this sample data

Vertex[type: Person, name: Foo] ---hasPet---> Vertex[type: Dog, name: Dog1]
Vertex[type: Person, name: Bar] ---hasPet---> Vertex[type: Cat, name: Cat1]
Vertex[type: Person, name: Bazz] ---hasPet---> Vertex[type: Dog, name: Dog2]
Vertex[type: Person, name: Bazz] ---hasPet---> Vertex[type: Dog, name: Dog3]

Then I wanted to find any Person-type vertex who has at least has pet which is a dog.

How could find all those Person-type vertices without traversing all the non-person type vertices?

I tried this query, but still it is traversing all pets of Bazz, I wanted to stop the traversal as soon as I found any matches since Bazz might have thousand other pets.

My query:

g.traversal().V().has("type", "Person").repeat(out("hasPet").simplePath()).until(has("type", "Dog")).simplePath().in().valueMap("name")

And this is the result:

[Foo]
[Bazz]
[Bazz]

What I like is:

[Foo]
[Bazz]

Join janusgraph-dev@lists.lfaidata.foundation to automatically receive all group messages.