Search code examples
databasegraphgremlintinkerpop

Gremlin Query: How to get all "internal" edges in the query so far?


So I'm trying to visualize the nodes so far in a gremlin query together with only the edges between these nodes; the "internal" edges if you may.

For example, I have this gremlin query:

g.V().hasLabel("Person").out("Expert in")

which results in a set of nodes. How do I, in a general matter, make a gremlin query to get all the edges between the nodes in this resultset?

Thanks for any help :)


Solution

  • I figured it out!

    This gremlin query should do the trick:

    g.V().hasLabel('Person') // <-- Nodes chosen so far; can be any query resulting in nodes
    .dedup()
    .union(outE(), inE()) 
    .groupCount()
    .unfold()
    .where(select(values).is(gt(1)))
    .select(keys)
    

    This takes the union of all outgoing and all ingoing edges, and then removes those edges that does not appear more than once. The result is all the edges between the nodes in the query so far :)