0

i am new to gremlin, here is what i am trying to do..

I have a 'product' vertex and a 'user' vertex. I have a product -> 'linkedto' -> user edge.. This edge has 2 properties 'type' and 'joinedon'. I am trying to fetch list of users who are linked to the product grouped by the 'type' property of the edge. The output should be something like this:

type: [

{name, email..., joinedon}, // user1 details + joinedon (from the edge)

{name, email..., joinedon}, // user2 details + joinedon (from the edge)

]

I have got to a point where i get grouped users with their details with this query


g.V(productid).outE('linkedto').as('a')
  .inV().as('b').group().by(select('a').values('type')).unfold()
  .project('type','user').by(select(keys)).by(select(values))

Questions:

  1. How can i get the joinedon from edge in result?
  2. How to select only specific fields from the edge and vertex (user) in the result?
varun
  • 55
  • 5
  • It would be helpful if you could provide the Gremlin steps that generate a small sample graph so that people can provide a good answer. An example of creating a small sample graph can be found here: https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – Kelvin Lawrence Mar 26 '21 at 14:36

1 Answers1

0

I would do the projection first, then the grouping.

g.V(1).outE('linkedto').
  project('type', 'name', 'email', 'joinedon').
    by(values('type')).
    by(inV().values('name')).
    by(inV().values('email')).
    by(values('joinedon')).
  group().
    by('type')
Bassem
  • 2,736
  • 31
  • 13