1

I am using gremlin REST server in my application and I want to create multiple edges to a vertex in a single query. I have the list of vertex ids from where to create edges to a single vertex.

For eg.- g.V(12,13,14,15).addEdge('uses', g.V(100))

I have tried many traversal steps but cannot get it to work.

Vipul Sharma
  • 768
  • 3
  • 11
  • 25

1 Answers1

5

You should look at the addE() step - here's one example for you can do it:

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(2,3,4,5,6).as('a').V(1).addE('likes').to('a')
==>e[13][1-likes->2]
==>e[14][1-likes->3]
==>e[15][1-likes->4]
==>e[16][1-likes->5]
==>e[17][1-likes->6]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • gremlin> g.V().hasLabel('earms_user') ==>v[19660804192] ==>v[24576008272] ==>v[19660804216] ==>v[19660804248] gremlin> g.V().hasLabel('earms_group') ==>v[18432004112] ==>v[20889604240] gremlin> g.V(19660804192,24576008272,19660804216).as('a').V(18432004112).addE('eu_eg').to('a') No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.V() is applicable for argument types: (java.lang.Long) values: [18432004112] Possible solutions: by(groovy.lang.Closure), is(java.lang.Object), any(), sum(), min(), max() – Vipul Sharma Sep 03 '17 at 08:38
  • gremlin> graph2 = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph2.traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.V(2,3,4,5,6).as('a').V(1).addE('likes').to('a') No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.V() is applicable for argument types: (java.lang.Integer) values: [1] Possible solutions: by(groovy.lang.Closure), is(java.lang.Object), any(), sum(), min(), max() – Vipul Sharma Sep 03 '17 at 08:42
  • what graph implementation are you using? and what version of tinkerpop? – stephen mallette Sep 03 '17 at 19:06
  • got it working using this - [link](https://stackoverflow.com/questions/38185325/how-to-add-multiple-edges-in-a-single-gremlin-query). Is this correct? – Vipul Sharma Sep 03 '17 at 19:21
  • I am using titan graph db and tinkerpop3. – Vipul Sharma Sep 03 '17 at 19:26
  • I have another doubt for which I have posted another question. Please check if you can answer that too - https://stackoverflow.com/questions/46027444/gremlin-only-add-a-vertex-if-it-doesnt-exists – Vipul Sharma Sep 03 '17 at 20:17
  • You can do what is in that link, but that is a single script, not a single traversal. If that's not a problem for you then you I guess you are fine, but ultimately it would be best to have a single traversal to do that work. If you are using Titan it could be that you have an older version that doesn't support the form of traversal I suggested. {{addE()}} should still work though in some capacity. If I were you, I'd study that a bit more. – stephen mallette Sep 04 '17 at 11:20
  • You might also consider using JanusGraph - http://janusgraph.org/ - so that you can get a newer version of TinkerPop to use. – stephen mallette Sep 04 '17 at 11:21