atulshgl
atulshgl

Reputation: 55

Gremlin: Unable to add edges to graph using console

I have created a graph using the following command and I am not able to a find a way in which I could add edges to it.

g = TinkerGraph.open().traversal()
g.addV('A1').addV('A2').addV('A3').addV('B3').

I have tried few variants of the following command to add edge.

g.V('A2').addEdge('pre',V('A1'))
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.addEdge() is applicable for argument types: (java.lang.String, org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) values: [pre, [GraphStep(vertex,[A1])]]

Upvotes: 3

Views: 2048

Answers (1)

Jason Plurad
Jason Plurad

Reputation: 6782

You didn't mention what version you're using, so I'll be referring to Apache TinkerPop 3.2.3. Here is a link to the documentation for the add edge step addE().

When you created your vertices, add vertex step addV() takes the vertex label as the parameter, not an id. Vertex labels aren't usually unique, so you're better off using the id.

gremlin> Gremlin.version()
==>3.2.3
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('A1').addV('A2').addV('A3').addV('B3')
==>v[3]
gremlin> g.V().valueMap(true)
==>[id:0,label:A1]
==>[id:1,label:A2]
==>[id:2,label:A3]
==>[id:3,label:B3]
gremlin> g.V(1L).addE('pre').to(g.V(0L))
==>e[4][1-pre->0]

Upvotes: 5

Related Questions