Joel Stevick
Joel Stevick

Reputation: 2028

Gremlin: how to extract a value from select

I have the following gremlin query:

gremlin> g.E('96b546e0-bf87-9649-2694-ccc29acec83e').as('e')
    .properties('foo').as('foo').select('e').outV().outE()
    .has('foo', __.select('foo')).valueMap()

    ==>{foo=bar2}

    ==>{foo=bar}

The above query is intended to start with an edge, and then identify all other edges from its outV that have the same value for edge-property 'foo'. The problem is that has() is expecting a value for the second argument, and select() returns a property

My Question: . How can I capture the value for 'foo' on the starting edge, and then use that value in a has() or where() to filter out edges that do not share the same value for property 'foo'?

Upvotes: 0

Views: 577

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

To compare one element's property with a property of another element, you use where():

g.E('96b546e0-bf87-9649-2694-ccc29acec83e').as('e').
  outV().outE().
  where(eq('e')).
    by('foo')

To exclude the original edge, you would do:

g.E('96b546e0-bf87-9649-2694-ccc29acec83e').as('e').
  outV().outE().
  where(neq('e')).
  where(eq('e')).
    by('foo')

Upvotes: 1

Related Questions