1

I have two gremlin queries. I want to filter out the output of one query based on the results of another query.

For example,

query 1: g.V().hasLabel('Person').values('name') gives the following output - John, Sam, Rocky

query 2: g.V().hasLabel('Friend').values('name') gives the following output - John

So, the final expected output I want is John

I have tried the following:

g.V().hasLabel('Person').where('names', g.V().hasLabel('Friend').values('name'))

But it doesn't seem to be working. Can anyone please help me here?

Avijit Dasgupta
  • 2,055
  • 3
  • 22
  • 36

1 Answers1

0

I'm curious why you are not using edges to determine a friend type relationship, but one way to re-write this is to just to reverse the parts.

g.V().hasLabel('Friend').values('name')).fold().as('friends').
  V().hasLabel('Person').
      where(within('friends')).by('name').by()
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38