0

I'd like to define a Gremlin query which returns all the nodes recursively till there are no more nodes available:

Node: ProductionEvent
Node: Product

What I've tried so far is the following...however, I'm not sure if the output is correct. Also, is it possible to print it out using the tree() function? And can I do the repeat function with the times function to get all nodes?

g.V().hasLabel('ProductionEvent').
                repeat(__.outE('consumes').simplePath()).times(3). 
                emit().dedup()  

Im expecting an output like this

Product1: consumed <--- ProductionEvent1 --> produced :Product2: consumed <--- ProductionEvent2 --> produced :Product3
haminoum
  • 71
  • 6
  • The `times()` function limits the number of repeats, in this case to 3. Have you tried running it without `.times(3)` – Tim Sexton May 17 '19 at 19:31
  • It also looks like you are expecting results from two different edges based on the traversal, `consumed` and `produced` but your query only looks at `consumes`. Can you post what your output actually looks like with the query you are using compared to the example of what you are expecting? – Tim Sexton May 17 '19 at 19:49
  • @TimSexton I receive many rows with the nodes: ==>v[9564QTBGLDVF9] ==>v[0481802604-322892015] ==>v[0481802604-322892067] ==>v[0481802604-322893909] ... I'm expecting something like: orderID -> producedProduct -> consumedProduct orderID -> producedProduct -> consumedProduct – haminoum May 19 '19 at 10:08

1 Answers1

0

I achieved results which am satisfied with. The query is

 g.V().hasLabel('ProductionEvent').has('orderID', 'XYZ')
      .repeat(__.out('consumes').in_('produces').simplePath()).emit().times(5)
      .dedup().limit(6).next()

From my understanding, the limit() and times() is necessary in order to improve the query execution time if the number of results is known in advance. And the simplepath() ensures that already visited paths are not revisited again.

haminoum
  • 71
  • 6