Gremlin - query properties from multiple entities

Viewed 89

I have product vertex and is_duplicate_with edge established between two product vertices. So the data model is like: product(id=1) -> is_duplicate_with(created_by=abc) -> product(id=2)

How to write a Gremlin query to get product id from the source product, created_by value from the is_duplicate_with edge and product id from the target product? In this sample, I want to get id=1, created_by=abc, id=2.

1 Answers

You can use a path step for this.

g.V('1').outE('is_duplicate_with').inV().hasId('2').
  path().
    by(id).
    by('created_by')

Or if you don't know the IDs up front

g.V().outE('is_duplicate_with').inV().
  path().
    by(id).
    by('created_by')

If you really need the key/value pairs in the result you can do something like this:

g.V().outE('is_duplicate_with').inV().
  path().
    by(project('id').by(id)).
    by(valueMap('created_by'))
Related