Get edge properties as well as source and target vertex ID in Gremlin query language

*爱你&永不变心* 提交于 2019-12-11 02:49:29

问题


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

My current database looks like that:

Edge:

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

Nodes:

_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]

What I am trying to get is

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

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

Is there a way to achieve that?

Thanks!

EDIT: Final query:

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]

回答1:


Use 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]


来源:https://stackoverflow.com/questions/52334577/get-edge-properties-as-well-as-source-and-target-vertex-id-in-gremlin-query-lang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!