使用Gremlin查询语言获取边缘属性以及源和目标顶点ID [英] Get edge properties as well as source and target vertex ID in Gremlin query language

查看:556
本文介绍了使用Gremlin查询语言获取边缘属性以及源和目标顶点ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索边缘属性作为值以及目标和源节点ID.

I am trying to retrieve the edge properties as values as well as the target and source node IDs.

我当前的数据库如下:

边缘:

_id _label _outV _inV name ID
0   edge   0     1    E    0

节点:

_id _label _name ID
0   node   A     0
1   node   B     1

我已经尝试过以下查询:

I have tried this query:

>g.V().as('a').outE('edge').as('b').inV().values('ID').as('to').
 select('b').valueMap().as('edge').
 select('a').values('ID').as('from').
 select('to','edge','from')
==>[to:0,edge:[ID:0,name:E],from:1]

我想要得到的是

[to:0,ID:0,name:E,from:1]

此外,Edge元素可以包含任意数量的属性.

Also the Edge elements could contain an arbitrary number of properties.

有没有办法做到这一点?

Is there a way to achieve that?

谢谢!

最终查询:

gremlin> g.V().outE('edge').limit(1).
......1>   project('weight','id','from','to').
......2>     by(coalesce(values('weight'),constant(''))).
......3>     by(id).
......4>     by(outV().id()).
......5>     by(inV().id())
==>[weight:,id:0,from:0,to:1]

推荐答案

使用project():

gremlin> g.V().has('name','marko').
......1>   outE().limit(1).
......2>   project('weight','id','from','to').
......3>     by('weight').
......4>     by(id).
......5>     by(outV().id()).
......6>     by(inV().id())
==>[weight:0.4,id:9,from:1,to:3]

这篇关于使用Gremlin查询语言获取边缘属性以及源和目标顶点ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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