4
votes

I am executing the gremlin query as follows:

g.V().hasLabel('A').has('label_A','A').emit().repeat(outE().inV()).valueMap()

Getting the desired output of nodes at multiple levels.

Along with the properties, I want to add a level property to the output. How can I achieve it?

2

2 Answers

1
votes

Adding another answer to point out you can avoid sack using loops as an alternative.

g.V().hasLabel('A').has('label_A','A').
      emit().
      repeat(group('x').by(loops()).by(valueMap().fold()).out()).
      cap('x') 
0
votes

You can use withSack for depth:

g.withSack(0).V().hasLabel('A').has('label_A','A').emit().
  repeat(sack(sum).
      by(constant(1)).
    out()).
  project('depth', 'properties').
    by(sack()).
    by(valueMap())

example: https://gremlify.com/ca32zczgvtkh6