addE
How to specify an edge.
Synopsis
addE('edgeLabel'). [ property('property_key', 'property_value'). ] from(outgoing_vertex).to(incoming_vertex)
Description
Edge data is inserted using addE
. A previously created edge label must be specified. Property key-value pairs may be
optionally specified. Specification of the vertices must exist to add an edge. The vertices
specified in the from()
and to()
steps must identify the
vertex by id, so the vertex must exist.
The addE()
step and the addV()
steps can be combined in a
single query.
Examples
For the examples below, the vertices are already specified and created:
g.V('dseg:/person/e7cd5752-bc0d-4157-a80f-7523add8dbcd').as('a'). V('dseg:/book/1001').as('b'). addE('authored').from('a').to('b')This query finds a vertex using a person id and temporarily assigns it to an identifier with
as('a')
. It repeats that with a book and as('b')
. The
addE('authored')
then constructs the edge between the person and the
book.Create an edge with an edge label
ate
between the vertices of a
person
and a meal
with the
propertymeal_date
:g.V().has('person', 'person_id', '6c09f656-5aef-46df-97f9-e7f984c9a3d9' as UUID).as('a'). V().has('type', 'lunch').has('meal', 'meal_id', 4004).as('b'). addE('ate').property('meal_date', '2019-08-21' as LocalDate).from('a').to('b')This query adds a property to the edge on creation. In this query, each vertex is discovered using a
has()
step that identifies the particular vertex.