Is it possible to search a vertex with a property value equal to id()

45 views
Skip to first unread message

Akhila Hegde

unread,
Dec 21, 2023, 3:25:20 AM12/21/23
to Gremlin-users
Hi

Is there a way in gremlin with Neptune DB to search a vertex with a value that is same as a property value of another vertex.

g.V('1234').has('property1', 'value1').V('value1').elementMap()

the graph has a vertex with id 1234. It has a property with key: property1 and value: value1

I want to traverse to another vertex with id() = value1, in the next step.

Is there a way to do it?

Kind regards,
Akhila

Kelvin Lawrence

unread,
Dec 21, 2023, 6:56:03 PM12/21/23
to Gremlin-users
In cases like this, the where...by syntax comes in handy. If the Vertex with an ID of '3' has a property called 'target' which has a value of '8', we can do:

g.V('3').as('a').
  out().
  where(eq('a')).
    by(id).
    by('target')


It's possible that one day the `has` step will be expanded to work with a traversal instead of just basic predicates, but until then, using the `where...by` construct is probably the easiest way to go.

Kelvin.
Reply all
Reply to author
Forward
0 new messages