Get edge properties as well as source and target v

2019-07-28 10:53发布

问题:

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]