如何在Tinkerpop中替换,合并或增加新边

时间:2018-08-04 02:32:36

标签: gremlin tinkerpop gremlin-server tinkergraph

当我尝试添加当前存在的边时,例如:

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

我收到这样的错误

{"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)

设置gremlin服务器或tinkergraph属性时,是否可以使用任何设置来合并,重新插入或忽略重复的边?

1 个答案:

答案 0 :(得分:2)

Gremlin Server或TinkerGraph中没有此类设置-upsert模式如下:

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