1

When I try to add an edge that currently exists, for example:

g.addE('person-ip').from(g.V('customer:testID')).to(g.V('tel:5555555555')).property(id, 'testEdgeId').next()

I get an error like this

{"message":"Edge with id already exists: testEdgeId","Exception-Class":"java.lang.IllegalArgumentException","exceptions":["java.lang.IllegalArgumentException"],"stackTrace":"java.lang.IllegalArgumentException: Edge with id already exists: testEdgeId\n\tat org.apache.tinkerpop.gremlin.structure.Graph$Exceptions.edgeWithIdAlreadyExists(Graph.java:1141)

Is there any setting I can use when setting up gremlin server or the tinkergraph properties that would allow duplicate edges to be merged, upserted, or ignored?

Wendell Blatt
  • 177
  • 1
  • 1
  • 10

1 Answers1

4

There are no such settings in Gremlin Server or TinkerGraph - The pattern for upsert is as follows and is described in more detail on this StackOverflow question:

g.E('testEdgeId').
  fold().
  coalesce(unfold(),
           V('customer:testID').as('start').
           V('tel:5555555555').
           addE('person-ip').
             from('start')
           property(id,'testEdgeId'))

UPDATE: As of TinkerPop 3.6.0, the fold()/coalesce()/unfold() pattern has been largely replaced by the new steps of mergeV() and mergeE() which greatly simplify the Gremlin required to do an upsert-like operation.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135