Search code examples
azure-cosmosdbgremlin

In Gremlin, after a Both() step, filter based on direction we just traversed


I'd like to be able to do separate filters based on the direction of the traversal after a Both() step. Here's a simplified query:

g.V("1").Both().Or(<direction was IN>, __.Has("tag", "some Value"))

I also considered doing separate In() and Out() steps, but I don't see a way to have the traverser branch in both directions.


Solution

  • I think it might be more clear to traverse In() and Out() separately. You can branch the traverser with union() and thus do:

    g.V("1").Union(In().has("tag","some Value"),
                   Out().has("tag","some Other Value"))