4

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?

noam621
  • 2,766
  • 1
  • 16
  • 26
Phoenix
  • 181
  • 2
  • 9

2 Answers2

1

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') 
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
0

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

noam621
  • 2,766
  • 1
  • 16
  • 26
  • Is it possible to modify the query to get the output as follows? Considering root at the zeroth level 1st level nodes as 1.1,1.2,1.3 so on. 2nd level nodes as 1.1.1,1.1.2,1.1.3(for nodes linked to 1.1), 1.2.1,1.2.2,1.2.3(for nodes linked to 1.2). Similarly for other nodes and next levels. – Phoenix Jun 10 '20 at 08:40
  • I added an example to your other question here: https://stackoverflow.com/questions/62302987/displaying-sub-levels-in-gremlin-query/62324262#62324262 – Kelvin Lawrence Jun 11 '20 at 12:26