简体   繁体   中英

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 :)

The out() step is a shorthand for outE().inV() so the first step to getting the edges is to explicitly traverse the edges so that they become part of the path history. You could get the edges from that history in a variety of ways - how about the path() step?

g.V().hasLabel("Person").outE("Expert in").inV().path()

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM