Skip to content

How do I retrieve multiple multi-properties in Gremlin?

I have a Person object that I’m writing to a graph like this:

gts.addV(newId).label('Person')
  .property(single, 'name', 'Alice')
  .property(set, 'email', '[email protected]')
  .property(set, 'email', '[email protected]')

Now I want to retrieve contents of the vertex. As documented, elementMap doesn’t work because it returns just a single property value for multi-properties. I tried values('name', 'email'), but that returned all of the properties in a flattened list instead of the nested structure I expected:

I’ve tried various combinations of values, project, and as/select, but I always get an empty result, a flat list, or a single value on multi-properties.

How can I query a vertex so that I get something like these results?

or

[name:'Alice', email:['[email protected]', '[email protected]']]

Answer

If you are just looking to return a map of the values you can achieve this using the valueMap() step:

g.V(newId).valueMap('name', 'email')

which will return:

[name:[Alice],email:[[email protected],[email protected]]]

If you want to return just the values you can do that by adding a select(values):

g.V().valueMap('name', 'email').select(values)

which returns

[[Alice],[[email protected],[email protected]]]