简体   繁体   中英

Displaying level in gremlin query

I am executing the gremlin query as follows:

gV().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?

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

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

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