Search code examples
gremlintinkerpop

Tinkerpop Gremlin Get Edges that go to vertices within a list


I'm trying to query for edges that go to vertices within an aggregated list. It sounds quite simple, and it should be, but I seem to be writing my queries wrong, and I just can't figure out why. Anyway, I'll use the Modern Toy Graph to make an example, that won't necessarily make much sense in this context, but still illustrates what I wish to do:

graph = TinkerFactory.createModern()
g = graph.traversal()

g.V().
  hasLabel('person').
    aggregate('x').
  outE().
    where(inV().is(within('x')))

What I'm doing is traversing to all 'person' vertices, aggregating them, then trying to get all the outgoing edges that lead to another vertex within that aggregated list. I expect the above query to return the edge labelled "knows" that goes between vertex 1 and 2, and the one between 1 and 4, however nothing is returned. If i simple want to get the vertices on the other end of those edges, rather than the edges themselves, the following works fine, returning vertex 2 and 4:

g.V().
  hasLabel('person').
    aggregate('x').
  out().
    where(within('x'))

So how can I get edges that lead to vertices already aggregated in a list?

(Once again, I'm aware this example doesn't make much sense within this particular graph, and I could easily query outE('knows'), but this query is relevant to a different graph.)

Thanks.


Solution

  • You can't use is() quite that way. An easy fix would be to just combine your "working" traversal with the one that doesn't:

    gremlin> g.V().hasLabel('person').
    ......1>   aggregate('x').
    ......2>   outE().
    ......3>   where(inV().where(within('x')))
    ==>e[7][1-knows->2]
    ==>e[8][1-knows->4]