Joe
Joe

Reputation: 7004

Following edges who's properties match one on the source vertex with Gremlin

I have a graph, and I want to follow the edges that contain a property that matches one on the vertex. E.g.

vertex         -------edge ---------> vertex
vertValue: 123        vert: 123       vertValue: 463

So in the above case, say I'm starting at the first vertex, I want to follow the edges that has the property 'vert' equal to it's 'vertValue'.

I've manage to make a query using where that manages to follow the edge:

g.V(id).as('verts')
  .outE().values('vert')
  .where(eq('verts'))
    .by('vertValue')

Problem, is I want to return the actual edge object. However, as I need to do the 'where' on the 'vert' value of the edge, in the query I'm doing a values('vert') so the result I get is just the value I'm testing, not the edge object. I want to do something like:

g.V(id).as('verts')
  .outE()
  .where(eq('verts'))
    .by('vertValue','vert')

To compare the 'vertValue' on the vertex, to the 'vert' value on the edge. But I can't seem to find a way to specify by on the 'input' values of the where.

Edit: Trying:

g.V("95c4a57a-9262-45b7-a905-8cca95d3ebb6").as('v').
  outE().
  where(eq('v')).
    by('vert').
    by('vertValue')

Returns an error:

Gremlin Query Execution Error: Select One: Get Projection: The provided traversal or property name of path() does not map to a value.

g.V("95c4a57a-9262-45b7-a905-8cca95d3ebb6").as('v').
  outE().
  where(eq('v')).
    by('vertValue').
    by('vert')

returns an empty array!

Upvotes: 0

Views: 552

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

You got really close to the solution. It's:

g.V(id).as('v').
  outE().
  where(eq('v')).
    by('vert').
    by('vertValue')

Upvotes: 0

Related Questions