Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

addE doesn't create more than 1 edge

34 views
Skip to first unread message

Anton Eroshenko

unread,
Dec 15, 2020, 6:22:56 AM12/15/20
to JanusGraph users

I'm trying to link one vertex (let's say Activity) with two others (person), I expect to have two
edges in result, the request below creates only one.

gremlin> g.V().hasLabel('Activity')
==>v[40984624]
gremlin> g.V().hasLabel('person').has('id', within('p1', 'p2'))
==>v[40996896]
==>v[41037952]
gremlin> g.V().hasLabel('Activity').addE('LINK').to(g.V().hasLabel('person').has('id', within('p1', 'p2')))
==>e[oe5mu-oefxs-b0np-oepeo][40984624-RESP->40996896]

Is it a bug or I'm missing something?

HadoopMarc

unread,
Dec 15, 2020, 10:06:56 AM12/15/20
to JanusGraph users
Hi Anton,

It is not a bug: the addE() step only adds one edge per traverser. Also, using g.V() twice is an anti-pattern. Try it the other way around, something like (not tested):
g.V().hasLabel('person').has('id', within('p1', 'p2')).as('a').addE('LINK').from('a')

Now the addE() step runs on two traversers.

HTH,     Marc

Op dinsdag 15 december 2020 om 12:22:56 UTC+1 schreef Anton Eroshenko:

Amiya

unread,
Dec 15, 2020, 2:03:31 PM12/15/20
to JanusGraph users
Marc is correct about "It is not a bug: the addE() step only adds one edge per traverser".
I think query by Mark will create a self link.

Below query might work (not tested)

g.V().hasLabel('Activity').as('a').
    V().has('person', 'id', within('p1', 'p2')).addE('LINK').from('a')

Anton Eroshenko

unread,
Dec 16, 2020, 4:03:30 AM12/16/20
to JanusGraph users
Thanks for your explanation. I got the idea, that "many" side of "one-to-many" relationship should go first when adding  edges.
Reply all
Reply to author
Forward
0 new messages