0

I used Jupyter notebook to insert the following vertices and edges into Neptune database.

%%gremlin

g.addV('my').property(T.id, '1').next()
g.addV('my').property(T.id, '2').next()
g.addV('my').property(T.id, '3').next()
g.addV('my').property(T.id, '4').next()
g.addV('my').property(T.id, '5').next()
g.addV('my').property(T.id, '6').next()
g.addV('my').property(T.id, '7').next()
g.addV('my').property(T.id, '8').next()

g.V('1').addE('parent').to(g.V('2')).next()
g.V('2').addE('parent').to(g.V('3')).next()
g.V('3').addE('parent').to(g.V('4')).next()
g.V('4').addE('parent').to(g.V('5')).next()

g.V('1').addE('parent').to(g.V('6')).next()
g.V('6').addE('parent').to(g.V('7')).next()
g.V('7').addE('parent').to(g.V('8')).next()

Then I used the follow query to find all ancestors for node "1". However, It only return node "5" and note "8", and highest level of ancestors.

How can I modify the query to get all the in-and-between ancestors like "2", "3", "4", "5", "6", "8"

%%gremlin -p v,oute,inv
g.V('1').repeat(out('parent')).until(outE('parent').count().is(0)).toList()
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
user1187968
  • 7,154
  • 16
  • 81
  • 152
  • Looks like this will fix the problem: `g.V('1').repeat(out('parent')).emit().until(outE('parent').count().is(0)).toList()` – user1187968 Jul 01 '21 at 17:55

1 Answers1

1

All you need to do is either add an emit() step after the repeat() or add path() step to the end of the query like this, depending on if you want the vertices or the path returned:

g.V().hasLabel('a').repeat(out('parent')).until(outE('parent').count().is(0)).emit()

g.V().hasLabel('a').repeat(out('parent')).until(outE('parent').count().is(0)).path()

bechbd
  • 6,206
  • 3
  • 28
  • 47