Joel Stevick
Joel Stevick

Reputation: 2028

Gremlin: how to find other edges with the same property

I have a graph with two vertices having id(s) 'a' and 'b'.

gremlin> g.V()

==>v[b]

==>v[a]

There are two edges from 'a' to 'b'.

gremlin> g.E()

==>e[a6b4bead-c161-5a61-d232-abfa2bfad54e][a-LIKES->b]

==>e[10b4bead-a0fc-8d2c-d69f-26b3e9e4c5d8][a-KNOWS->b]

gremlin> g.E().valueMap(true)

==>{id=a6b4bead-c161-5a61-d232-abfa2bfad54e, semantics=social, label=LIKES}

==>{id=10b4bead-a0fc-8d2c-d69f-26b3e9e4c5d8, semantics=social, label=KNOWS}

My question: given an id for one of the edges, I would like to find all other edges with the same value for the property "semantics". For example, given a.LIKES.id, I would like to execute a query that will return a.KNOWS using the value a.LIKES.semantics.

I started with:

g.E('a6b4bead-c161-5a61-d232-abfa2bfad54e') .property('semantics').as('semantics')...this is where I am stuck

Thanks, Joel

Upvotes: 0

Views: 408

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

where() in conjunction with a by() modulator will do the job:

g.E('a6b4bead-c161-5a61-d232-abfa2bfad54e').as('e').
  outV().inE().
  where(eq('e')).by('semantics'). // return edges with the same semantics property value
  where(neq('e'))                 // ... except the one we started with

Upvotes: 3

Related Questions