Gremlin 查询:如何在 valuemap 中包含标签时排除 ID?
Gremlin Queries: How to exclude ID while including label in valuemap?
所以我有一个像这样的 gremlin 查询:
g.V().hasLabel('Person').valueMap(true, 'name')
现在这将创建一个包含 fields/columns、'Label'、'ID' 和 'name' 的值映射,但是如何从中排除 'ID'?
我只想将 'Label' 和 'name' 作为结果包括在内。
非常感谢任何帮助,谢谢! :)
你可以使用WithOptions
来控制它。
这里是一个使用 air-routes 数据集的例子
gremlin> g.V('3').valueMap('city').with(WithOptions.tokens,WithOptions.ids)
==>[id:3,city:[Austin]]
gremlin> g.V('3').valueMap('city').with(WithOptions.tokens,WithOptions.labels)
==>[label:airport,city:[Austin]]
使用 WithOptions 的另一个答案可能有效,但我在尝试时收到一条错误消息(我使用 API 将 gremlin 查询作为字符串发送,所以它可能是 server-side 的 API).
不过,我想出了另一种方法。
有标签:
g.V().hasLabel('Person').project('label', 'name').by(label).by(values('name').fold())
ID:
g.V().hasLabel('Person').project('id', 'name').by(id).by(values('name').fold())
所以我有一个像这样的 gremlin 查询:
g.V().hasLabel('Person').valueMap(true, 'name')
现在这将创建一个包含 fields/columns、'Label'、'ID' 和 'name' 的值映射,但是如何从中排除 'ID'?
我只想将 'Label' 和 'name' 作为结果包括在内。
非常感谢任何帮助,谢谢! :)
你可以使用WithOptions
来控制它。
这里是一个使用 air-routes 数据集的例子
gremlin> g.V('3').valueMap('city').with(WithOptions.tokens,WithOptions.ids)
==>[id:3,city:[Austin]]
gremlin> g.V('3').valueMap('city').with(WithOptions.tokens,WithOptions.labels)
==>[label:airport,city:[Austin]]
使用 WithOptions 的另一个答案可能有效,但我在尝试时收到一条错误消息(我使用 API 将 gremlin 查询作为字符串发送,所以它可能是 server-side 的 API).
不过,我想出了另一种方法。
有标签:
g.V().hasLabel('Person').project('label', 'name').by(label).by(values('name').fold())
ID:
g.V().hasLabel('Person').project('id', 'name').by(id).by(values('name').fold())