Search code examples
gremlin

Gremlin query to return all edge properties and also inV and outV


Before the new ReferenceElementStrategy default setting, Gremlin query g.E() would return edge ID, label, inV, outV, and all the properties. What query should I use to return the same data with ReferenceElementStrategy enabled? g.E().valueMap().with(WithOptions.tokens).by(unfold()) returns everything except inV and outV.


Solution

  • For right now the answer is project():

    gremlin> g.E(12).union(valueMap(true),
    ......1>               project('inV','outV','inVLabel','outVLabel').
    ......2>                 by(inV().id()).
    ......3>                 by(outV().id()).
    ......4>                 by(inV().label()).
    ......5>                 by(outV().label())).unfold().
    ......6>               group().
    ......7>                 by(keys).
    ......8>                 by(select(values))
    ==>[inV:3,id:12,inVLabel:software,weight:0.2,outVLabel:person,label:created,outV:6]
    

    but for next release of 3.4.4 it will be elementMap():

    gremlin> g.E(11).elementMap()
    ==>[id:11,label:created,IN:[id:3,label:software],OUT:[id:4,label:person],weight:0.4]