Inserting data with traversal API

Inserting data with traversal API.

The Traversal API can be used to insert data into DSE Graph.

Procedure

  1. Add a vertex:
    g.addV('person').property('personId', 1).property('name','Julia Child').property('gender', 'F')
    The addV() step must identify the vertex label, and can be followed by key and value pairs in property() steps for any properties that are added.
  2. To add an edge using only the graph API, the two vertices that are connected by the edge can be assigned variables that can be used in the add() statement:
    juliaChild = g.V().has('person', 'personId', 1).next()
    artOfFrenchCookingVolOne = g.V().has('book', 'bookId', 1001).next()
    g.V(juliaChild).addE('authored').to(artOfFrenchCookingVolOne)
    or alternatively, the query can be constructed without variables:
    g.V().has('person','name','Julia Child')
         .addE('authored')
         .to(g.V().has('book','name','The Art of French Cooking, Vol. 1')
    The outgoing vertex, juliaChild, is connected to the incoming vertex, artOfFrenchCookingVolOne with a to()step, to create and authored edge with addE(),
    If the edge has properties, the key and value pairs are appended to the addE() statement, similar to the addV() statement with property():
    g.V().has('person','name','Julia Child')
        .addE('created')
        .to(g.V().has('recipe','name','Beef Bourguignon'))
        .property('createDate', '1956-01-10')
  3. A property can also be added to a previously created vertex, like jamieOliver:
    jamieOliver = g.V().has('person', 'name', 'Jamie Oliver').next()
    jamieOliver.property('gender', 'M').property('nickname', 'jimmy')
    A property() value can also be modified by simply doing a similar traversal with a different value.
  4. A property can also be added to a previously created edge by constructing a query that finds the edge and changes or adds the property with property():
    g.V().has('person','name','Julia Child')
        .outE('created')
        .has('createDate', '1956-01-10')
        .property('createDate', '1956-09-09')