0

I wish to traverse in a unidirectional way but facing difficulty in going back and fetching the vertex which is filtered in path . Please help.

g.V().hasLabel('states').as('s').
  in().hasLabel('url').as('u').
  select('s').
  where(and(inE('exporting').has('forward','states'),
            inE('release').has('forward','states'))).
  select('u')
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
Varun Tahin
  • 299
  • 1
  • 2
  • 15
  • And what exactly is the problem? The traversal looks fine to me, although it contains a few unnecessary steps. – Daniel Kuppitz Sep 17 '18 at 15:33
  • Thanks for formatting . On running this query it is returning the 'u' variable vertices but , what I want is filtered vertices . That is on running the where clause it should come back and fetch only those 'u' vertices which are filtered using where on path and not all. – Varun Tahin Sep 18 '18 at 04:37
  • That should be the case. But let me simplify your query, maybe that'll help. – Daniel Kuppitz Sep 18 '18 at 14:15

1 Answers1

1

Since all your filters pretty much depend on s, it makes sense to use match() step.

g.V().hasLabel('states').
  match(__.as('s').in().hasLabel('url').as('u'),
        __.as('s').inE('exporting').has('forward','states'),
        __.as('s').inE('release').has('forward','states')).
  select('u')

That, at least, makes it easier to read. However, there's an even simpler way to write your query, which requires no labels at all:

g.V().hasLabel('states').
  and(inE('exporting').has('forward','states'),
      inE('release').has('forward','states')).
  in().hasLabel('url')
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34
  • Thanks, but this is not giving me filtered url. It is actually fetching all the url vertices which are tied with states label. I wish to retrieve the url vertices going back the filtered path – Varun Tahin Sep 19 '18 at 06:10
  • That's what it does. Maybe provide a small sample graph and show the expected result to explain what you need. – Daniel Kuppitz Sep 19 '18 at 06:20