如何在Gremlin中检索多个多属性? [英] How do I retrieve multiple multi-properties in Gremlin?

查看:74
本文介绍了如何在Gremlin中检索多个多属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要写入图表的Person对象:

gts.addV(newId).label('Person')
  .property(single, 'name', 'Alice')
  .property(set, 'email', 'alice1@example.invalid')
  .property(set, 'email', 'alice2@example.invalid')

现在我想检索顶点的内容。正如文档所述,elementMap不起作用,因为它只为多个属性返回单个属性值。我尝试了values('name', 'email'),但返回了扁平列表中的所有属性,而不是我预期的嵌套结构:

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

我尝试了valuesprojectas/select的各种组合,但始终得到空结果、平面列表或多个属性的单个值。

如何查询顶点以获得类似的结果?

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

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

推荐答案

如果您只是希望返回值的映射,则可以使用valueMap()step

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

返回:

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

如果只想返回值,可以通过添加select(values)

来实现

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

返回

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

这篇关于如何在Gremlin中检索多个多属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆