Skip to content
Advertisement

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', 'alice1@example.invalid')
  .property(set, 'email', 'alice2@example.invalid')

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:

['Alice', 'alice2@example.invalid', 'alice1@example.invalid']

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?

['Alice', ['alice2@example.invalid', 'alice1@example.invalid']]

or

[name:'Alice', email:['alice2@example.invalid', 'alice1@example.invalid']]

Advertisement

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:[alice1@example.invalid,alice2@example.invalid]]

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],[alice1@example.invalid,alice2@example.invalid]]

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement